JAXB 编组器将超类编组为根元素并使用 xsi:type
我正在尝试将子类编组为超类,并将 xsi:type 信息作为 XML 根元素属性。
目前这就是我所拥有的(比方说..):
- XMLDOCUMENTTYPE 是 XMLINVOICETYPE 的超类,
- 编组 XMLINVOICETYPE 会给我
- 将 XMLINVOICETYPE 实例转换为 XMLDOCUMENTTYPE 实例,然后编组它仍然会给我
- 创建使用 JAXB 注释进行注释的包装器对象似乎做到这一点,但现在我必须抓住第一个子节点,
例如:
jaxbWrapper.setXmlDocumentType(xmlInvoiceTypeInstance);
// will do the trick but extra root
我想得到如下:
<XMLDOCUMENTTYPE ... ... xsi:type="XML_INVOICE_TYPE">
</XMLDOCUMENTTYPE>
知道如何做到这一点吗?
I'm trying to marshal a sub-class as super-class with xsi:type information as the XML Root element attributes.
Currently this is what I have (let's say..):
- XMLDOCUMENTTYPE is a super class of XMLINVOICETYPE
- marshalling XMLINVOICETYPE will give me
<xmlInvoiceType>
- Casting XMLINVOICETYPE instance to XMLDOCUMENTTYPE instance and then marshalling it would still give me
<xmlInvoiceType>
- Creating a wrapper object annotated with JAXB annotation seems to do the trick, but now I have to grab the first child-node
e.g.:
jaxbWrapper.setXmlDocumentType(xmlInvoiceTypeInstance);
// will do the trick but extra root
What I'd like to get is as follow:
<XMLDOCUMENTTYPE ... ... xsi:type="XML_INVOICE_TYPE">
</XMLDOCUMENTTYPE>
Any idea how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试编组:
Try marshalling:
仅当类型不与类匹配时,才会呈现 xsi:type。
试试这个:
xsi:type is only rendered, if the type does not match the class.
Try this: