我想这样的XML:如何在子类上使用JAXB @XmlValue?
@XmlRootElement(name="simple")
class Simple {
@XmlValue
public String contents;
}
但现在我需要做的简单类是另一个子类:
<simple>Foo</simple>
我可以通过JAXB类,看起来像这样成功地做到这一点类像这样:
@XmlRootElement(name="simple")
class Simple extends OtherClass {
@XmlValue
public String contents;
}
失败与@XmlValue is not allowed on a class that derives another class.
我不能轻易重构的超远(因为这样,我们正在使用@XmlE在包装类上的lementRef)。有没有解决方法可以让我注释我的子类来生成这个简单的XML?
哇,感谢详细的例子!不幸的是,我的应用程序容器(Karaf)使用ServiceMix中的jaxb-impl/jaxb-xjc,我相信它很难切换。 –
@ChrisDolan - 这取决于您的应用程序环境。 JAXB提供者可以在模型级配置。在以下文章中,默认情况下在使用JAXB RI的GlassFish服务器中使用MOXy:http://blog.bdoughan.com/2010/08/creating-restful-web-service-part-35.html –
@ChrisDolan - 当使用JAXB RI时,您可能会将'OtherClass'标记为@XmlTransient:http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html –