JAXB:第三方或外部超类上的 @XmlTransient [英] JAXB: @XmlTransient on third-party or external super class

查看:15
本文介绍了JAXB:第三方或外部超类上的 @XmlTransient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些有关 JAXB 2.1 的以下问题的帮助.

I need some help regarding the following issue with JAXB 2.1.

示例:我创建了一个扩展抽象类 Person 的 SpecialPerson 类.现在我想使用 JAXB 将我的对象结构转换为 XML 模式.因此,我不希望 Person XML 类型出现在我的 XML 架构中以保持架构简单.相反,我希望 Person 类的字段出现在 SpecialPerson XML 类型中.

Sample: I've created a SpecialPerson class that extends a abstract class Person. Now I want to transform my object structure into a XML schema using JAXB. Thereby I don't want the Person XML type to appear in my XML schema to keep the schema simple. Instead I want the fields of the Person class to appear in the SpecialPerson XML type.

通常我会将类级别的注释@XmlTransient 添加到Person 代码中.

Normally I would add the annotation @XmlTransient on class level into the Person code.

问题是 Person 是第三方类,我无法在此处添加 @XmlTransient.我如何告诉 JAXB 它应该忽略 Person 类而不注释该类.是否可以以某种方式在外部进行配置?

The problem is that Person is a third-party class and I have no possibility to add @XmlTransient here. How can I tell JAXB that it should ignore the Person class without annotating the class. Is it possible to configure this externally somehow?

你以前有过同样的问题吗?任何想法这个问题的最佳解决方案是什么?

Have you had the same problem before? Any ideas what the best solution for this problem would be?

推荐答案

好吧,这在你知道什么的过程中很痛苦.最后,在筛选了许多博客帖子之后,这就是我所做的,

OK, this was a pain in the you-know-what. Finally, after sifting through many a blog postings, here's what I did,

像这样在第三方类"包中添加了一个package-info.java类,

added a package-info.java class in the 'third-party class' package like this,

@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.NONE)打包第三方包;

@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.NONE) package third-party-package;

就我而言,它只是一个包裹,所以很容易.显然,您必须为每个单独的包结构执行此操作.我还没有尝试在主包级别这样做.

In my case, it was just one package so it was easy. Obviously, you will have to do this for for every separate package structure. I haven't tried doing it at a master package level.

这篇关于JAXB:第三方或外部超类上的 @XmlTransient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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