jaxb-v2 icon indicating copy to clipboard operation
jaxb-v2 copied to clipboard

Jaxb xjc generation is not 100% consistent for xs:choice

Open dcabasson opened this issue 7 years ago • 1 comments

Xjc generation of a xs:choice produce code that is not always the same. The difference is in the ordering of the @XmlElementRefs in the generated Java class. This is causing some pain with the cache and change detection. The generated code should always be the same for the same Xml Schema.

When generating from :

   <xsd:complexType name="randomImportType">
        <xsd:choice maxOccurs="unbounded">
            <xsd:element name="aaa" nillable="true" type="xsd:int" />
            <xsd:element name="bbb" nillable="true" type="xsd:int" />
            <xsd:element name="ccc" nillable="true" type="xsd:int" />
            <xsd:element name="ddd" nillable="true" type="xsd:int" />
            <xsd:element name="eee" nillable="true" type="xsd:int" />
            <xsd:element name="fff" nillable="true" type="xsd:int" />
        </xsd:choice>
    </xsd:complexType>

I have had :

   @XmlElementRefs({
        @XmlElementRef(name = "aaa", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "ccc", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "ddd", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "fff", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "eee", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "bbb", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false)
    })
    protected List<JAXBElement<Integer>> aaaOrBbbOrCcc;

or :

    @XmlElementRefs({
        @XmlElementRef(name = "bbb", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "fff", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "aaa", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "ddd", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "ccc", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "eee", namespace = "urn:helloWorld/sample/ibm/TestImport", type = JAXBElement.class, required = false)
    })
    protected List<JAXBElement<Integer>> aaaOrBbbOrCcc;

generated. Gradle cache considers (correctly) that those 2 are not the same and retrigger all the downstream tasks.

Expected behaviour : The generated code should always be the same, probably in the order of the original document.

Sample gradle project exposing the issue : xjc-choice-order.zip

run gradlew xjc at the root and the 2 files :

  • module-1/src/main/java/helloworld/sample/ibm/testimport/RandomImportType.java
  • module-2/src/main/java/helloworld/sample/ibm/testimport/RandomImportType.java

Are not the same.

dcabasson avatar Apr 26 '18 17:04 dcabasson

Duplicates https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8169102

dcabasson avatar Apr 27 '18 16:04 dcabasson