JSON in Java the Right Way -- Action, Jackson!
Comment by reda on April 10, 2012 at 8:36am Hi,
I have difficulties understanding @JsonManagedReference and @JsonBackReference
From the javadoc:
@JsonBackReference:
Annotation used to indicate that associated property is part of two-way linkage between fields; and that its role is "child" (or "back") link. Value type of the property must be a bean: it can not be a Collection, Map, Array or enumeration.
@JsonManagedReference
Annotation used to indicate that annotated property is part of two-way linkage between fields; and that its role is "parent" (or "forward") link. Value type (class) of property must have a single compatible property annotated with JsonBackReference.
Which means that in the relationship of customer/orders where the customer is the parent and order is the child we should have some thing like:
Class customer {
@JsonManagedReference //Isn't order the child? How can the javadoc states that its role is "parent"
List<Order> order ;
}
Class Order {
@JsonBackReference //Isn't the customer the parent? How can the javadoc states that its role is "child"
Customer customer;
}
Please clarify this for me.
Comment by Tatu Saloranta on April 10, 2012 at 9:48am Javadoc looks bit confusing; but what it tries to say is that _property_ that points to child(ren) is the "parent link" (from parent to child). Term "forward link" is probably better. Comment is not to mean that what is being pointed to was the parent entity, on contrary.
Hope this helps!
Comment by reda on April 10, 2012 at 10:21am Thanks for your quick reply.
++
Comment
© 2013 Created by Tatu Saloranta.
Powered by
You need to be a member of Jackson JSON User Group to add comments!
Join Jackson JSON User Group