Jackson - serialization of entities with birectional relationships (avoiding cycles)

Jackson 2.0 does support full cyclic object references. See "Jackson 2.0 released" (section 'Handle Any Object Graphs, even Cyclic ones!') for an example.

Basically, you will need to use new @JsonIdentityInfo for types that require id/idref style handling. In your case this would be both Parent and Child types (if one extends the other, just add it to super type and that's fine).


very handy interface implementation is provided in jackson 2 library as

@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Parent { ....

@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Child { ....

in maven

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.0.2</version>
</dependency>

@StaxMan provided a nice link to start from