users@jaxb.java.net

Re: Ordering of enum values in XJC

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 26 Jul 2006 17:55:11 -0700

Kenny MacLeod wrote:
> If I have a schame with the following type:
>
> <simpleType name="TestEnum">
> <restriction base="NMTOKEN">
> <enumeration value="b"/>
> <enumeration value="a"/>
> <enumeration value="c"/>
> </restriction>
> </simpleType>
>
> The when XJC turns this into a java enum type, then it will re-arrange
> the enumeration values into alphabetical order:
>
> @XmlEnum
> public enum TestEnum {
>
> @XmlEnumValue("a")
> A("a"),
> @XmlEnumValue("b")
> B("b"),
> @XmlEnumValue("c")
> C("c");
> }
>
> While I appreciate that the permitted enum values in the XML Schema are
> not strictly speaking ordered, the values in a java enum type are.
>
> Is there any reason why XJC couldn't retain the ordering of enum values
> in the generated java? Information is being lost during the translation.

There's no reason. We just thought it would be more helpful to order
methods and fields. But I see your point that with enums, you might want
to see constants in the original order.

> Should I file an issue for this?

Yes, that would be helpful.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com