Hi,
In client, I am getting below response in client side when trying to read value from mapLane.
What I am getting.. (@Customer and @ContactInfo is the object name)
{
"@Customer": null,
"firstName": "kumar",
"lastName": "Raju",
"dob": "1990-09-09",
"contactInfo": [
{
"@ContactInfo": null,
"email": "test@gmail.com",
"phone": "1252425262"
}
]
}
Expected is
{
"firstName": "kumar",
"lastName": "Raju",
"dob": "1990-09-09",
"contactInfo": [
{
"email": "test@gmail.com",
"phone": "1252425262"
}
]
}
My Client code:
swim.downlinkMap().hostUri(HOST).nodeUri('/customer').laneUri('details').open().didUpdate((key,value) => {
console.log({...value.toAny()});})
I am not sure what I am missing.. Could you point the mistake.
Hard to say for sure without seeing the server code. But you can skip to past the ---
for my suggested fix.
My hypothesis is that this is actually the expected behavior. I assume that
firstName
, lastName
, dob
, and contactInfo
contactInfo
is ContactInfo[]
Then the recon
(not JSON) serialization of your object will look like:@Customer{firstName:kumar,lastName:Raju,dob:"1990-09-09",contactInfo:{@ContactInfo{email:"test@gmail.com",phone:"1252425262"}}}
, assuming that you used annotations instead of manually writing the Form<Customer>
.
When a serialization looks like @foo{bar:a,baz:b}
, the swim.structure
representation of this is actually a three-length Record
(i.e. a collection of Items
) whose first item is an Attr
with key foo
and undefined value; second Item
is a Slot
with key bar
and value a
; last Item
is a Slot
with key baz
and value b
. It is by design that an Attr
appears "raised" even though it is in the same structural level. JSON does not differentiate between "special" key-value pairs like Attr
vs Slot
, so when you translate an Attr
-containing object to JSON, it simply appears as a "regular" key-value pair with @
in it.
---
To get everything except for the first Item
in a Record
, you should be able to call tail()
on it. On the shorter example above, you should see (in JSON) {bar:a,baz:b}
. In your example, you would need to do this twice to handle the nested ContactInfo
type object.
@brohitbrose
Please find server code.. I hope this helps..
Plane:
@SwimRoute("/customer")
private AgentRoute<Customer> customer;
Lane:
@SwimLane("details")
MapLane<String, Customer> view = this.<String, Customer>mapLane().didUpdate((key, newValue, oldValue) -> {
System.out.println("the new value is " + newValue.toString());
});
customerDetails
and contactInfoDetails
(this might take a little more processing, maybe something like contactInfoDetails.getItem(0).tail()
for the first value since it's an Array)as defined above
@meepeek Good questions.
Please do let us know if you have any other questions. Also one question for you, how did you hear about the Swim platform?