Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell JAXB not to generate @XmlSchemaType Annotation

Tags:

soap

jaxb

following xsd (partial):

<xs:complexType name="Fruit">
    <xs:sequence>
        <xs:element name="type" type="FruitType"/>
    </xs:sequence>
</xs:complexType>
<xs:simpleType name="FruitType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="ABC">
        </xs:enumeration>
        <xs:enumeration value="DEF">
        </xs:enumeration>
        <xs:enumeration value="GHI">
        </xs:enumeration>
        <xs:enumeration value="JKL">
        </xs:enumeration>
    </xs:restriction>
</xs:simpleType>

Generating code with xjc will generate the following java code (FruitType is an Enum):

    @XmlElement(required = true)
    @XmlSchemaType(name = "string")
    protected FruitType fruit;

When generating a SOAP WebService with JAX-WS the following element will be generated:

<xs:element name="type" type="xs:string"/>

Which ist obviously wrong. I'd expect this to be

<xs:element name="type" type="FruitType"/>

If I delete this line by hand

    @XmlSchemaType(name = "string")

in my Java Code everything in the wsdl is fine :

<xs:element name="type" type="tns:FruitType"/>

So the question is: How can I tell JAXB not to generate the @XmlSchemaType?

like image 358
dbaer Avatar asked Oct 26 '15 13:10

dbaer


1 Answers

Instead of referencing FruitType with type

<xs:complexType name="Fruit">
    <xs:sequence>
        <xs:element name="type" type="FruitType"/>
    </xs:sequence>
</xs:complexType>

the trick ist to have a simpleType inline:

    <xs:complexType name="Fruit">
    <xs:sequence>
        <xs:element name="type">
            <xs:simpleType>
                <xs:restriction base="FruitType"/>
            </xs:simpleType>
        </xs:element>
    </xs:sequence>
</xs:complexType>

this will generate the correct java file and WSDL:

<xs:element name="type" type="tns:FruitType"/>
like image 104
dbaer Avatar answered Jan 02 '23 18:01

dbaer