JAXB generates factory methods that create a JAXBElement from an object instance only if your XSD contains a complexType definition and a separate element definition using this complexType with the same name, for example:
<complexType name="my-type"> ... </complexType> <element name="my-type" type="tns:my-type"/>
In this case, JAXB will not annotate the created class with the @XmlRootElement annotation, but will provide the factory methods needed to create the JAXBElement from the object instance. This way you can easily serialize type instances without a root element as root elements.
So, you just need to add an βelementβ declaration with the same name in addition to any complexType definition that you intend to use as a top-level element, and ObjectFactory will generate the expected factory methods.
Mirror klemm
source share