schemagen: order of generated enum values

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

schemagen: order of generated enum values

Holger Brands
Hello,

we are upgrading from JAXB version 2.1.10 to a newer version,
because we want to be able to generate our schemas with Java 8 as runtime.

With JAXB version 2.2.11 we observe some differences in the generated schema files for enums.
It seems that the enum values are generated in random order.

For example from this class:

@XmlType
public final class EnumTest {

    @XmlEnum
    public static enum MyEnum {
        ONE,
        TWO,
        THREE,
        FOUR,
        FIVE,
        SIX
    }

    @XmlElement(name = "count")
    private MyEnum mycount;

    public EnumTest() {
        // NOP
    }

    public MyEnum getCount() {
        return mycount;
    }
}

the following schema is generated:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="enumTest" final="extension restriction">
    <xs:sequence>
      <xs:element name="count" type="myEnum" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:simpleType name="myEnum">
    <xs:restriction base="xs:string">
      <xs:enumeration value="THREE"/>
      <xs:enumeration value="FOUR"/>
      <xs:enumeration value="ONE"/>
      <xs:enumeration value="TWO"/>
      <xs:enumeration value="SIX"/>
      <xs:enumeration value="FIVE"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

As you can see, the generated enum values are not in declaration order (as it was with
JAXB 2.1.10). If you generate the schema again, a different order could be the result.
It would be nice, if this could be fixed, as we get a lot of diffs when comparing existing
with newly generated schema files. I think this behaviour can be observed since JAXB 2.2.5.

On a side note, nested enums are ignored, if they are not referenced somewhere else.
For example, if the MyEnum above would not be referenced in the EnumTest class,
it would not be generated in the schema file. This is also a difference to JAXB 2.1.10.

I know that these two differences are not a compatibility issue,
but I wanted to ask if this was intentional.

Thanks,
Holger





Loading...