ISSUE:
When using xjc, a bindings.xjb and a xsd file are provided. I have a enumeration inside my xsd, called "EnumType", which contains a single element called "I24". Jaxb creates "EnumType.java" with a "I_24" element and so

EnumType.valueOf("I24")

Throws exception.


WHAT I TRIED:

I have the following xsd:

<xs:simpleType name="EnumType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="I24" />
    </xs:restriction>
</xs:simpleType>

And i have the following bindings.xjb:

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:annox="http://annox.dev.java.net" xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" jaxb:extensionBindingPrefixes="xjc annox" version="2.1">

    <jaxb:bindings schemaLocation="xsdFile.xsd">
        <jaxb:bindings node="//xs:simpleType[@name='EnumType']/xs:restriction/xs:enumeration[@value='I24']">
            <jaxb:typesafeEnumMember name="I24"/>
        </jaxb:bindings>
    </jaxb:bindings>

</jaxb:bindings>

This makes my enum have a member called "I24" inside my java code and i like it. BUT i need this kind of thing for all the future cases when a new enum member must be added, for example "X24".


WHAT I WANT:
I want all the generated enumeration names to be EXACTLY as they are specified inside my XSD, without providing all of them inside my xjb file.

Also, my generated classes must implement Serializable, so i made a xjb file which is as follows and works for this last requirement. I have to extend this file in order to accomplish enumeration name forcing:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2000/10/XMLSchema-instance" xs:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" jaxb:version="2.0">

    <jaxb:globalBindings fixedAttributeAsConstantProperty="true">
        <jaxb:serializable uid="1" />
    </jaxb:globalBindings>
</jaxb:bindings>

0 Answers