Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin should not generate List-properties if maxOccurs defaults to 1 #116

Open
ashauer opened this issue Jul 30, 2020 · 1 comment
Open

Comments

@ashauer
Copy link

ashauer commented Jul 30, 2020

For the simplify-plugin, all examples in the reference have choice-elements with maxOccurs="unbounded", which correctly results in List-properties. But if maxOccurs is not specified it defaults to 1, so there should not be List-properties but singular fields.

Example:

<xs:complexType name="typeWithElementsProperty">
  <xs:choice> <!-- maxOccurs defaults to 1! -->
    <xs:element name="foo" type="xs:string"/>
    <xs:element name="bar" type="xs:int"/>
  </xs:choice> 
</xs:complexType>

should rather result in

    @XmlElement(name = "foo", type = String.class)
    protected String foo;  // no List!
    @XmlElement(name = "bar", type = Integer.class)
    protected Integer bar;  // no List!

for usage of <simplify:as-element-property/>

@DSkyline
Copy link

I'm not sure if this is the correct place to post the question but kind of looks similar to what i need. The behaviour the @ashauer needs is what i get from the default jaxb2-maven plugin.
So by not targeting the elements in my bindings.xjb file using <simplify:as-element-property/> jaxb2-maven plugin generates elements as a single object IF <xs:choice> is used and maxOccurs is 1.
But what i'm wondering is if it's possible to "override" the maxOccurs value in the child elements and if there's element with maxOccurs="1", then will be generated as a single object?
So, i still want to use <xs:choice maxOccurs="unbounded">so that i can add more elements inside of that complexType, but not all the elements should be generated as a List.

(Using example from above :)

<xs:complexType name="typeWithElementsProperty">
  <xs:choice maxOccurs="unbounded">
    <xs:element name="foo" type="xs:string"/>
    <xs:element name="bar" type="xs:int" maxOccurs="1"/>
 </xs:choice> 
</xs:complexType>

Would result in

@XmlElement(name = "foo", type = String.class)
protected List<String> foo;  // List!
@XmlElement(name = "bar", type = Integer.class)
protected Integer bar;  // no List!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants