You will need to leverage a factory class annotated with @XmlRegistry
(usually called ObjectFactory
). That class will contain a create
method for each possible root element annotated with @XmlElementDecl
. See this article I wrote for more details and examples.