Jaxb not adding the @XMLRoot element.

There are those cases where you are trying to build an object Model from XSD and sees that there is no @XMLRootElement tag added to the root element in the stub and your unmarshelling starts failing. The  basic idea is that if we can statistically guarantee that a complex type won't be used by multiple different tag names, XJC put @XmlRootElement. 

Try for the basic schema http://www.w3schools.com/schema/ here. You see the root element gets generated.


The issue happens when you have something like this

<schema>
 <element name="Employee" type="inc:CTEmployee" />
 <complexType name="CTEmployee" />
</schema> 

You see the Employee element is not tagged with the @XMlRootElement in the stub. The Assumption that XJC does is that "your schema might be used by other schema's that XJC isn't compiling right now".


So basic fix is avoid doing the Complex type defined outside on same name for the root element and it will work fine or avoid the ambugity by removing multiple references like the ones shown above.

Comments

Popular posts from this blog

'jasypt.encryptor.password' or one of ['jasypt.encryptor.privateKeyString', 'jasypt.encryptor.privateKeyLocation'] must be provided for Password-based or Asymmetric encryption

Field or property 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - Spring Batch

java.security.spec.InvalidKeySpecException: Only RSAPrivate(Crt)KeySpec and PKCS8EncodedKeySpec supported for RSA private keys