highsource / jaxb2-basics

Useful plugins and tools for JAXB2.
BSD 2-Clause "Simplified" License
109 stars 54 forks source link

simplify: generating erroneous List properties instead of simple objects #85

Open sfrenkiel opened 7 years ago

sfrenkiel commented 7 years ago

Please check this small project: https://github.com/sfrenkiel/basicstest. It contains this xsd:

<xs:element name="wrapper">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="element" />
            <xs:choice>
                <xs:group ref="seq1"/>
                <xs:group ref="seq2"/>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:group name="seq1">
    <xs:sequence>
        <xs:element name="oneA"/>
        <xs:element name="b"/>
    </xs:sequence>
</xs:group>
<xs:group name="seq2">
    <xs:sequence>
        <xs:element name="twoA"/>
        <xs:element name="b"/>
    </xs:sequence>
</xs:group>

If you run the pom and look at the generated class Wrapper.java, you'll see that all the properties are generated as lists of objects, not simple objects:

public class Wrapper {

protected List<Object> element;
protected List<Object> twoA;
protected List<Object> oneA;
protected List<Object> b;

...

There are 3 xsd files in the project. If you replace the contents of test.xsd with either works1.xsd or works2.xsd, and rerun maven, you'll see that Wrapper.java is generated as expected:

public class Wrapper {

@XmlElement(required = true)
protected Object element;
protected Object oneA;
protected Object b;

...

I suspect having element 'b' appear twice under the Wrapper hierarchy is causing the issue, although as 'b' only appears under separate elements within a 'choice' construct I don't believe this should be happening. Worse though is that this seems to cause the other properties to be generated as lists as well.

BTW, wrapping seq1 and seq2 in complexTypes also resolves the problem, however this approach isn't possible in the actual code I am working with.

Any insight is appreciated. Thanks!