Is there a way to influence the serialization process with @JsonIdentityInfo so that it inserts the whole object instead of referencing the id?
@Entity
@JsonIdentityInfo(
generator = ObjectIdGenerators.IntSequenceGenerator.class,
property = "linkLabel")
public class LinkLabel implements Serializable {
//...
}
So instead of referencing "otherObj" with id 1, Jackson should include the whole object.
{
"objects": [{
"id": 1,
"otherObj": [{
"id": 1,
...
}, {
"id": 3,
...
}]
},
"id": 2,
"otherObj": [1] <-- referencing otherObj with id 1
]
}
like here:
{
"objects": [{
"id": 1,
"otherObj": [{
"id": 1,
...
}, {
"id": 3,
...
}]
},
"id": 2,
"otherObj": [{
"id": 1, <-- desired format, whole object
...
}]
]
}
We have bidirectional references, so @JsonManagedReference and @JsonBackReference doesn't work properly. This behavior is described here (http://wiki.fasterxml.com/JacksonFeatureObjectIdentity).
Like said in the comments and from the links, @JsonIdentityInfo and the Jackson Generators doesn't seem to have an option to enable inserting objects instead of ids.
After more research we finally found this: deserialize Jackson object in JavaScript containing JsonIdentityInfo
This was exactly the scenario we had and we are now using JSOG, which is optimized for bidirectional references and it works like a charm on server and client (AngularJS) side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With