Reputation: 299
I have xsd, that is using famous convention:
<xsd:element name="name" type="Type">
<!-- ... -->
</xsd:element>
<xsd:complexType name="Type">
<!-- ... -->
<xsd:complexType/>
And because of that, when I generate classes with xjc tool I don't have @XmlRootElement annotation. I found a solution on the stackoverflow, that is using simple binding for xjc:
<jxb:bindings schemaLocation="myschema.xsd" node="/xs:schema">
<jxb:globalBindings>
<xjc:simple/>
</jxb:globalBindings>
</jxb:bindings>
when I generate classes with xjc with -extension -b flags, I've got XmlRootElement annotation. The problem is, that name of the class is no longer correct. I expect to have class "Type" that is using "" as a root element. But I receive class "Name".
I've spent almost 2 days on this issue...
Is there any way to create class with proper name and XmlRootElement annotation?
Upvotes: 3
Views: 569
Reputation: 149017
Using the xjc:simple
Extension
The generated class name isn't incorrect, it is just that the class name was derived from the global element rather than the complex type.
Standard Behaviour
Without the xjc:simple
extension global elements that correspond to named complex types will have a corresponding @XmlElementDecl
annotation on the ObjectFactory
class. As a result the object will be wrapped in an instance of JAXBElement
during marshalling and unmarshalling.
For More Information
Upvotes: 1