Question

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;
  }

}
Was it helpful?

Solution

EclipseLink MOXy's @XmlInverseReference can be used when the object and property are of the same type. The current problem with this use case is that the same property needs to be used for both directions of the relationship.

What Your Seeing

When a property is annotated with @XmlInverseReference, for marshalling MOXy will treat that property as being @XmlTransient.

Enhancement Request

I have entered the following enhancement request to support this type of behaviour. Please add any additional details that you feel are relevant.

For More Information on @XmlInverseReference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top