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

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

问题描述

在经由XJC编译器的XSD生成Java,我总是得到类型java.langString与匿名simpleTypes内容是这样的:

When generating Java from an XSD via the XJC compiler, I always get the type java.langString 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。
(之前你问:不,我不能改变的模式,并使其适应XJCs错误。)
非常感谢!

We are using JAXB 2.1.3. (Before you ask: no, I cannot change the schema and adapt it to XJCs bugs.) Thanks so much!

推荐答案

您必须把你的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天全站免登陆