是否可以在对象和属性为同一类型的情况下使用@XmlInverseReference? [英] Is it possible to use @XmlInverseReference where object and property are of same type?

查看:108
本文介绍了是否可以在对象和属性为同一类型的情况下使用@XmlInverseReference?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MOXy JAXB实现,并广泛使用@XmlInverseReference批注.但是,我最近遇到了这种方法似乎不起作用的情况.如果我有一个包含一个字段的类具有与父类相同类型的属性的类,则应用@XmlInverseReference似乎完全抑制了该属性的编组.省略注释会产生可预测的StackoverflowException.

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.

有人遇到过这个问题,并发现了MOXy的有效解决方案吗?

Has anybody encountered this problem and discovered an effective solution with MOXy?

违规类的快速示例:

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

}

推荐答案

EclipseLink MOXy @XmlInverseReference当对象和属性属于同一类型时可以使用.该用例当前的问题是,关系的两个方向都需要使用相同的属性.

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.

您所看到的

当用@XmlInverseReference注释属性时,为了进行编组,MOXy将该属性视为@XmlTransient.

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

增强请求

我已输入以下增强请求以支持这种行为.请添加您认为相关的其他详细信息.

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

有关@XmlInverseReference

For More Information on @XmlInverseReference

这篇关于是否可以在对象和属性为同一类型的情况下使用@XmlInverseReference?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆