I have two classes as shown below in a bi-directional Many to Many relationship:
Parent implements Serializable{
@ManytoMany(//declaration for join table)
@JsonBackReference
@com.fasterxml.jackson.annotation.JsonIgnore
Set <Child> childSet;
}
Child implements Serializable{
@ManytoMany(//declaration for join table)
@JsonManagedReference
@com.fasterxml.jackson.annotation.JsonIgnore
Set <Parent> parentSet;
// other getter and setters
}
I make a call in my DAO to get a particular parent. Alongwith the parent details I want to fetch the children of the parent. Something like this:
Hibernate.initialize(parent.getChildSet()); //this works perfectly
// and I get the details of parent along with the children in my DAO call.
But when I do the below in my business service while returning the data to the controller the children are omitted from the parent json string.
jacksonMapper.writeValueAsString(parent);
So i removed the @JsonIgnore on Child attribute inside Parent class thinking that jackson might understand that these fields are not to be ignored while writing to a string as shown below. But it still does ignore them! :(
Parent implements Serializable{
@ManytoMany(//declaration for join table)
@JsonBackReference
//@com.fasterxml.jackson.annotation.JsonIgnore
Set <Child> childSet;
}
Any idea where I might be going wrong?