Reputation: 21
I noticed the the simpleType or complexType is defined and the types are used in the declarations of multiple element in a schema file, the simpleType or complexType is generated a method signature as "JAXBElemet createXyz(Xyz xyz)". But I'm not sure if it is root reason.
Upvotes: 1
Views: 134
Reputation: 403451
In order to marshal an object to XML, JAXB needs to know the name of the XML element to be used. It gets this either from (a) the @XmlRootElement
annotation on the class, or (b) by wrapping the object in a JAXBElement
, which contains the element name.
If XJC generates a class without @XmlRootElement
, then the factory methods for that class in ObjectFactory
will instead use JAXBElement
wrappers, to provide the required marshalling information.
You may then ask why XJC decides to generate @XmlRootElement
for some classes but not others, but that's been asked on SO before, so go and have a look around for that one.
Upvotes: 1