If your class does not have an @XmlRootElement
annotation then you can wrap it in an instance of JAXBElement
. If you generated your classes from an XML Schema then the generated ObjectFactory
may have a convenience method for you.
I have written more about this use case on my blog: