问题描述
使用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.
是有办法实现,实现某种转换器?可以使用?
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:
这篇关于JAXB - 从XSD生成类 - 将枚举转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!