0

I have parent child relationship build this way (came from legacy system)

@Entity
@Table
class A implements Serializable {

    ........
    @jsonmanagedreference("test")  
    @OneToMany(mappedBy="PK.id", fetch = FetchType.LAZY,)
    Set<B> b = new HashSet<B>()

    ......
    setters / getters

}



@Embeddable
class PK {

   @jsonbackreference("tets") // can't find it 
   @ManyToOne
   @JoinColumns
   A a

}

@Entity
@Table
class B implements Serializable {

   @EmbeddedId
   private PK pk;

   setters / getters 

}

It works fine with regular operations, the problem is I can not serialize A object because circular reference. After I tried to add @jsonmanagedreference to A.b and @jsonbackreference to PK.a it did not work because it could not find JsonBackReference, is there a way to manage parent child relationship during serialization if child in Embedded class or nested?

antohoho
  • 950
  • 2
  • 17
  • 37

1 Answers1

0

I used this solution: Read embedded object in Jackson

It worked for me, just using @JsonUnwrapped on embedded class reference and mapping the embedded id with: @JsonIdentityInfo

@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "yourEmbeddedIdAtribute")