I'm using the MOXy JAXB implementation and make quite extensive use of the @XmlInverseReference annotation. However, I've recently encountered a scenario where this approach doesn't seem to work. If I have a class containing a field with a property that's the same type as the parent class, applying @XmlInverseReference seems to suppress the marshalling of that property altogether. Omitting the annotation yields a predictable StackoverflowException.
Has anybody encountered this problem and discovered an effective solution with MOXy?
A quick sample of the offending class:
public class Person {
private Long id;
private Person spouse;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@XmlInverseReference(mappedBy="spouse")
public Person getSpouse() {
return spouse;
}
public Person setSpouse(Person spouse) {
this.spouse = spouse;
}
}