Is it possible to use @XmlInverseReference where object and property are of same type?

前提是你 提交于 2020-01-24 13:08:08

问题


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

}

回答1:


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.

  • https://bugs.eclipse.org/361296

For More Information on @XmlInverseReference

  • http://blog.bdoughan.com/2010/07/jpa-entities-to-xml-bidirectional.html


来源:https://stackoverflow.com/questions/7811771/is-it-possible-to-use-xmlinversereference-where-object-and-property-are-of-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!