如何告诉 JAXB 不要生成 @XmlSchemaType 注释 [英] How to tell JAXB not to generate @XmlSchemaType Annotation
问题描述
跟随 xsd(部分):
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>
用xjc生成代码会生成如下java代码(FruitType是一个Enum):
Generating code with xjc will generate the following java code (FruitType is an Enum):
@XmlElement(required = true)
@XmlSchemaType(name = "string")
protected FruitType fruit;
使用 JAX-WS 生成 SOAP WebService 时,将生成以下元素:
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"/>
如果我手动删除这一行
@XmlSchemaType(name = "string")
在我的 Java 代码中,wsdl 中的一切都很好:
in my Java Code everything in the wsdl is fine :
<xs:element name="type" type="tns:FruitType"/>
所以问题是:如何告诉 JAXB 不要生成 @XmlSchemaType?
So the question is: How can I tell JAXB not to generate the @XmlSchemaType?
推荐答案
而不是用 type 来引用 FruitType
Instead of referencing FruitType with type
<xs:complexType name="Fruit">
<xs:sequence>
<xs:element name="type" type="FruitType"/>
</xs:sequence>
</xs:complexType>
内联 simpleType 的诀窍是:
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>
这将生成正确的 java 文件和 WSDL:
this will generate the correct java file and WSDL:
<xs:element name="type" type="tns:FruitType"/>
这篇关于如何告诉 JAXB 不要生成 @XmlSchemaType 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!