I have below two classes with a circular link, I did not put getters and setters for convenience
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "i") public class A{ int i; B b1; B b2; } @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "i") public class B { int i; AI a; }
if the references A.b1 and A.b2 refer to the same object B, I got serialized json as shown below:
{ "i": 1, "b1": { "i": 2, "a": 1 }, "b2": 2 }
But my expected result:
{ "i": 1, "b1": { "i": 2, "a": 1 }, "b2": { "i": 2, "a": 1 } }
I checked Jackson's source code as an id / reference jackson store for a previously used object, and if the same link is used by any other object, it will use the identifier instead of serializing the entire object, which is good if the objects remain in the same circular chain, but if they donβt stay in one chain, then this is strange, as my example shows.
Can anyone help get the expected result with the @identityinfo annotation?
source share