JAXB - 从XSD生成类 - 将枚举转换为字符串 [英] JAXB - generating classes from XSD - converting enums to strings

查看:452
本文介绍了JAXB - 从XSD生成类 - 将枚举转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JAXB,我们直接生成Java bean。在XSD中,我们有一个枚举类型:

Using JAXB, we generate our Java beans directly. In the XSD, we have an enumerated type:

  <xs:simpleType name="promptBeforeCloseType">
    <xs:restriction base="xs:string">
     <xs:enumeration value="default"/>
     <xs:enumeration value="always"/>
     <xs:enumeration value="never"/>
    </xs:restriction>
  </xs:simpleType>

JAXB使用此类型为字段生成枚举类型。我们希望将它转换为生成的Java类中的String,因为这些类映射到ActionScript类,并且ActionScript中没有枚举类型。

JAXB generates an enumerated type for the field using this type. We would like to have it converted to a String in the generated Java class, because those classes are mapped to ActionScript classes, and there is no enumerated type in ActionScript.

是有办法实现,实现某种转换器?可以使用 XmlJavaTypeAdapter

Is there a way to do it, implementing some kind of converter ? May be with XmlJavaTypeAdapter ?

推荐答案

您可以强制XJC不生成枚举。请参阅此文档:

You can force XJC to not generate enums. See the "Global Binding Declarations" section of this document:


如果typesafeEnumBase设置为
xsd:string,则指定该值为
的全局方式所有简单类型
定义直接派生或
间接从xsd:string和
枚举facet应该被
默认绑定到类型安全枚举。 如果将
typesafeEnumBase设置为空的
字符串,,默认情况下,没有简单的类型定义
会绑定到类型安全的枚举
类。

这篇关于JAXB - 从XSD生成类 - 将枚举转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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