For some reason JsonIdentityInfo serialises the depth of one child but not the other. My example:
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "id")
class A {
  private long id;
  private B last;
  // Getters, setters...
}
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "id")
class B {
  private long id;
  private A a;
  private C c1;
  private C c2;
  // Getters, setters...
}
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "id")
class C {
  private long id;
  private Set<A> as;
  private B last;
  // Getters, setters...
}
I serialise object B it serialises child A a to some depth, serialises C c1 to few levels deep. But C c2 only gets the reference.
I want A a; C c1; C c2; serialised only to first depth or also include c2 regardless of depth.
Just use @JsonUnwrapped annotation on the property c1 and c2 in class B. i.e.
@JsonIdentityInfo(generator = 
ObjectIdGenerators.IntSequenceGenerator.class, property = "id")
class B {
  private long id;
  private A a;
  @JsonUnwrapped
  private C c1;
  @JsonUnwrapped
  private C c2;
  // Getters, setters...
}
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