如何告诉JAXB不要生成@XmlSchemaType批注 [英] How to tell JAXB not to generate @XmlSchemaType Annotation

查看:560
本文介绍了如何告诉JAXB不要生成@XmlSchemaType批注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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是枚举):

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?

推荐答案

而不是引用类型为FruitType的

Instead of referencing FruitType with type

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

具有简单内联的窍门:

    <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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆