I have bi-directional relationship like this...
Person.java
public class Person{ @JsonIgnore @OneToMany(targetEntity=PersonOrganization.class, cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="person") private Set<PeopleOrg> organization; ..... }
PersonOrganization.java
public class PersonOrganization{ @JsonIgnore @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="PERSONID", nullable=false) private Person person; }
Even with @JsonIgnore
annotation I am getting infinite recursion error when trying to retrieve Person records. I have tried new annotations in 1.6 version. @JsonBackReference
and @JsonManagedReference
. Even then I am getting infinite recursion..
With @JsonBackReference("person-organization")
on Person
and @JsonManagedReference("person-organization")
on PersonOrganization
org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.entity.Person["organization"]->org.hibernate.collection.PersistentSet[0]->com.entity.PersonOrganization["person"]->com.entity.Person["organization"]->org.hibernate.collection.PersistentSet[0]...
Even If I interchange the annotations, I am still getting this exception.. Please let me know if there is something wrong with the mappings or the way I am using JSON annotations. Thanks
I've run into this before. But after moving @JsonIgnore from private field to getter of the field, infinite recursion is gone. So my wild guess is that @JsonIgnore might no work on private field. However, javadoc or tutorial of Jackson Java JSON-processor do not mention about this, so I cannot be 100% sure. Just for your information.
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