Reputation: 911
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..):
<xmlInvoiceType>
<xmlInvoiceType>
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?
Upvotes: 0
Views: 1344
Reputation: 61
xsi:type is only rendered, if the type does not match the class.
Try this:
// create the type and add childs and attributes ...
XmlInVoiceType xmlInVoice = new XmlInVoiceType();
// map the element to object to force xsi:type
final JAXBElement<?> object = new JAXBElement<>(new QName("http://your/namespace/xmlinvoice", "xmlinvoice"), Object.class, xmlInVoice);
Upvotes: 0
Reputation: 43671
Try marshalling:
new JAXBElement(new QName("XMLDOCUMENTTYPE"), XMLDOCUMENTTYPE.class, xmlInfoiceTypeInstance)
Upvotes: 2