JAXB:匿名简单类型作为枚举? [英] JAXB: Anonymous simple types as enums?

查看:24
本文介绍了JAXB:匿名简单类型作为枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当通过 XJC 编译器从 XSD 生成 Java 时,对于具有匿名 simpleType 的元素,我总是得到 java.lang.String 类型,如下所示:

When generating Java from an XSD via the XJC compiler, I always get the type java.lang.String for elements with anonymous simpleTypes like this:

    <xsd:element name="Product">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Product1"/>
            <xsd:enumeration value="Product2"/>
            <xsd:enumeration value="Product3"/>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

当然,我想要一个枚举.有没有办法诱使 XJC 生成并使用一个?

Of course, I want an enumeration for this. Is there a way to trick XJC into generating and using one?

我们使用的是 JAXB 2.1.3.注意:在您提问之前,不,我无法更改架构并使其适应 XJC 的错误.

We are using JAXB 2.1.3. Note: before you ask, no, I cannot change the schema and adapt it to XJC's bugs.

推荐答案

你必须放入你的XJC文件:

You have to put into your XJC File:

<jxb:bindings node="//xsd:element[@name='Product']/xsd:simpleType">
    <jxb:typesafeEnumClass name="ProductType" />
</jxb:bindings>

<jxb:bindings node="//xsd:element[@name='Produkt']">
    <jxb:bindings node="./xsd:simpleType">
        <jxb:typesafeEnumClass name="ProduktType" />
    </jxb:bindings>
</jxb:bindings>

这篇关于JAXB:匿名简单类型作为枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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