Question

I'm using xjc via maven to generate sources. I'm using an XSD and a bindings file. I would like my generated classes to have the annotation @XmlType(name = ""). I can't see how to set the name to be blank.

I've tried (amongst other ideas) annotating using annox:annotate("http://annox.dev.java.net") with annox:class="javax.xml.bind.annotation.XmlType" but this adds another @XmlType annotation rather than replacing/overwriting the existing one.

Is there a way to set the @XmlType's name to be blank?

Was it helpful?

Solution

The name is left blank if the Type is an anonymous type. Check here (Section "Mapping a Class").

To do that, you need to declare your type inside an <element> tag. The following schema shows an example:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Container">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Item" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="Item">
        <xs:complexType >

        </xs:complexType>
    </xs:element>

</xs:schema>   

Here, element Item is of an anonymous type, and here's the generated class:

@XmlType(name = "")
@XmlRootElement(name = "Item")
public class Item {


}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top