FkJ FkJ - 2 months ago 36
Java Question

JAXB: is typesafeEnumMemberName="generateName" customizable?

I was having some issues to import a WSDL that have a XSD with numeric enums.

Adding typesafeEnumMemberName="generateName" to my global bindings solved it, but the generated enum items are meaningless...

Example:

<simpleType name="dm_UF">
<restriction base="string">
<length value="2"/>
<enumeration value="50"/>
<enumeration value="51"/>
<enumeration value="52"/>
<enumeration value="53"/>
<enumeration value="98"/>
</restriction>
</simpleType>


@XmlEnumValue("50")
VALUE_24("50"),

@XmlEnumValue("51")
VALUE_25("51"),

@XmlEnumValue("52")
VALUE_26("52"),

@XmlEnumValue("53")
VALUE_27("53"),

@XmlEnumValue("98")
VALUE_28("98");


Instead of VALUE_ + itemPosition, I'd like to have VALUE_ + itemValue to avoid the developer making some mistake.

Changing the XSD is not an option, since there it's a government standard and there are lots of other numeric enums, some with thousands of items...

I'm using the cxf-codegen-plugin version 3.1.5 + krasa-jaxb-tools 1.4

Is it possible?

Thanks

FkJ FkJ
Answer

I missed the fromValue method that is generated with the enums.

So instead of doing GeneratedEnum.VALUE_<<itemPosition>>,

I can do GeneratedEnum.fromValue("<<itemValue>>").

Comments