There is a placeholder answer over at the unofficial guide with a link to an article which (to me) seems quite unrelated.
I use XJC to generate my JAXB classes and while most of them map to each other as expected, some elements get mapped to JAXBElement<Foo>
. This is most annoying for graphs with cycles, where sometimes the parent node of a Foo element will be the JAXBElement<Foo>
, which doesn't itself have a parent property, breaking the cycle.
I can think of various workarounds, but it would be much nicer if someone could explain this behaviour to me. Why does JAXB sometimes map a <Foo>
element to JAXBElement<Foo>
instead of Foo?
JAXBElement is used to preserve the element name/namespace in use cases where enough information is not present in the object model. The most common occurence is with substitution groups:
With Substitution Group:
Will generate:
Without Substitution Group:
If you remove the substitution group:
The following class will be generated:
You may also get a JAXBElement when you unmarshal, compare the following examples:
To avoid mapping to JAXBElement? I have done this things it work for me :
Save this file in the xml file and supply as binding files.
Reference Link
Generate JAXB classes using eclipse dont forget to give binding files created with above xml and check "Allow Vendor extensions" as below:
With changes i am able Get rid of JAXBElement in classes generated xjc for convert xsd to JAXB generated classes.