How to tell JAXB not to generate @XmlSchemaType Annotation

after 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 using xjc will produce the following java code (FruitType is Enum):

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

When creating a SOAP WebService with JAX-WS, the following element will be created:

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

Which is obviously wrong. I expect it to be

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

If I delete this line manually

  @XmlSchemaType(name = "string") 

everything in wsdl is fine in my java code:

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

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

+6
source share
1 answer

Instead of referencing FruitType with type

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

the trick has a simple type inline type:

  <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 create the correct Java file and WSDL:

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

All Articles