After a few months and a lot of research, I implemented my own solution to keep my domain without Jackson dependencies.
public class Parent { private Child child; public Child getChild(){return child;} public void setChild(Child child){this.child=child;} } public class Child { private Parent parent; public Child getParent(){return parent;} public void setParent(Parent parent){this.parent=parent;} }
First, you must declare each of your entities a bi-directional relationship:
public interface BidirectionalDefinition { @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id", scope=Parent.class) public interface ParentDef{}; @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id", scope=Child.class) public interface ChildDef{}; }
After that, you can configure the display configuration of the object:
ObjectMapper om = new ObjectMapper(); Class<?>[] definitions = BidirectionalDefinition.class.getDeclaredClasses(); for (Class<?> definition : definitions) { om.addMixInAnnotations(definition.getAnnotation(JsonIdentityInfo.class).scope(), definition); }
Pablo Oct 30 '15 at 4:17 2015-10-30 04:17
source share