JAXB Code Generation: Limited Type & # 8594; how to remove the zero occurrence field?

I am using JAXB 2.1 to create Java classes from multiple XSD files that I cannot modify (based on the WSDL file actually), and I have a problem with a complex type constraint. On restrictions changes the entry configuration from minOccurs="0" maxOccurs="unbounded"to minOccurs="0" maxOccurs="0". Thus, this field is no longer required in a restricted type. But actually JAXB generates a limited class with [0..1] power instead of 0.

By the way, generation is customizable with <xjc:treatRestrictionLikeNewType />, so the XSD restriction does not map to Java class inheritance.

Here is an example:

This is how a field is defined in complex type A:

<element name="qualifier" type="CR" maxOccurs="unbounded" minOccurs="0"/>

Here's how to restrict the same field to another complex type B that bounds A:

<element name="qualifier" type="CR" minOccurs="0" maxOccurs="0"/>

, A, :

@XmlElement(name = "qualifier")
protected List<CR> qualifiers;

B :

protected CR qualifiers;

JAXB XmlElement JAXB / . ? , JAXB qualifiers ? , , , .

, ?

!!

+3
2

, minOccurs = "0" , ? , , - , .

0

, .

<xjc:treatRestrictionLikeNewType /> <xjc:simple />. , !

, JAXB;)

0

Source: https://habr.com/ru/post/1750450/


All Articles