Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jaxb doesn't generate enums with base integer

Tags:

java

maven

jaxb

xsd

I have following xsd:

<xs:simpleType name="resultcode">
    <xs:restriction base="xs:integer">
        <xs:enumeration value="0" id="Approved_no_error">
            <xs:annotation>
                <xs:appinfo>
                    <jxb:typesafeEnumMember name="Approved_no_error"/>
                </xs:appinfo>
            </xs:annotation>
        </xs:enumeration>

JAX-B just does nothing, no errors, no warnings just doesn't generate this class. If change base from xs:integer to xs:string then it's ok. But I need exactly integer values.

I generate classes with maven:

<groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>AuthGateway</id>
            <goals>
                <goal>xjc</goal>
            </goals>

And question 2. JAX-B and IDE (IDEA) doesn't allow whitespaces in id attrribute. Why?

<xs:enumeration value="0" id="Approved_no_error"> - ok
<xs:enumeration value="0" id="Approved no error"> - not ok

Is it correct behaviour?

like image 470
Dmitrii Borovoi Avatar asked Dec 20 '11 00:12

Dmitrii Borovoi


1 Answers

You can use an external binding file to get the behaviour that you are looking for:

  • JAXB enumeration with numeric values
  • http://blog.bdoughan.com/2011/08/jaxb-and-enums.html
like image 53
bdoughan Avatar answered Sep 28 '22 11:09

bdoughan