javaxmljaxbxsi

JAXB marshaller to marshal super-class as root-element and use xsi:type


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..):

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?


Solution

  • Try marshalling:

    new JAXBElement(new QName("XMLDOCUMENTTYPE"), XMLDOCUMENTTYPE.class, xmlInfoiceTypeInstance)