加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 编组时如何防止JAXB绑定@XmlRootElement的超类方法?

发布时间:2020-12-14 05:31:26 所属栏目:Java 来源:网络整理
导读:我有一个类被注释为@XmlAccessorType(XmlAccessType.NONE)的@XmlRootElement.我遇到的问题是超类的方法被绑定,当我不希望它们被绑定,并且不能更新类.我希望有一个注释,我可以放在根元素类,以防止这种情况发生. 例: @XmlRootElement@XmlAccessorType(XmlAcce
我有一个类被注释为@XmlAccessorType(XmlAccessType.NONE)的@XmlRootElement.我遇到的问题是超类的方法被绑定,当我不希望它们被绑定,并且不能更新类.我希望有一个注释,我可以放在根元素类,以防止这种情况发生.

例:

@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Person extends NamedObject {

    @XmlElement
    public String getId() { ... }

}

我希望只有注释@XmlElement on Person上的方法才会被绑定和编组,但是超类的方法也被绑定.所得到的XML然后具有太多的信息.

如何防止超类的方法被绑定而不必注释超类本身?

解决方法

根据这个StackOverflow的帖子:
How can I ignore a superclass?

JAX-B无法忽略超类而不修改超类.
引用该职位的相关部分:

Update2: I found 07001 for a similar problem. That thread resulted in an 07002,which was marked as a duplicate of 07003,which resulted in the @XmlTransient annotation. The comments on these bug reports lead me to believe this is impossible in the current spec.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读