I'm having a bidirectional many to many relationship in my entities. See the example below:
public class Collaboration {
@JsonManagedReference("COLLABORATION_TAG")
private Set<Tag> tags;
}
public class Tag {
@JsonBackReference("COLLABORATION_TAG")
private Set<Collaboration> collaborations;
}
When I try to serialize this to JSON, I'm getting the following exception: `
"java.lang.IllegalArgumentException: Can not handle managed/back reference 'COLLABORATION_TAG': back reference type (java.util.Set) not compatible with managed type (foo.Collaboration).
Actually, I know this makes sense because the javadoc explicitly states that you can't use @JsonBackReference on Collections. My question is, how should I address this problem? What I've done for now is remove the @JsonManagedReference annotation on the parent side, and added the @JsonIgnore on the child side. Could someone tell me what the side effects are of this approach? Are there any other suggestions?