Reputation: 21
This is a snippet from the XSD associated with the WSDL in question.
<complexType name="ValueMapEntry">
<complexContent>
<restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
<sequence>
<choice maxOccurs="unbounded" minOccurs="0">
<element ref="{namespace...}bi"/>
<element ref="{namespace...}a"/>
<element ref="{namespace...}s"/>
<element ref="{namespace...}b"/>
<element ref="{namespace...}t"/>
<element ref="{namespace...}d"/>
<element ref="{namespace...}dt"/>
<element ref="{namespace...}dur"/>
<element ref="{namespace...}de"/>
<element ref="{namespace...}l"/>
<element ref="{namespace...}f"/>
</choice>
</sequence>
<attribute name="k" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
</restriction>
</complexContent>
</complexType>
So we have a complex type that contains a list of some other complex types all of which extend the same base class (called Value)
This is all good and generates this in the client java code.....
@XmlElements({
@XmlElement(name = "de", namespace = "namespace...", type = ValueDecimal.class),
@XmlElement(name = "l", namespace = "namespace...", type = ValueLong.class),
@XmlElement(name = "d", namespace = "namespace...", type = ValueDate.class),
@XmlElement(name = "dt", namespace = "namespace...", type = ValueDateTime.class),
@XmlElement(name = "dur", namespace = "namespace...", type = ValueDuration.class),
@XmlElement(name = "a", namespace = "namespace...", type = ValueAnySimpleType.class),
@XmlElement(name = "f", namespace = "namespace...", type = ValueDouble.class),
@XmlElement(name = "t", namespace = "namespace...", type = ValueTime.class),
@XmlElement(name = "s", namespace = "namespace...", type = ValueString.class),
@XmlElement(name = "b", namespace = "namespace...", type = ValueBoolean.class),
@XmlElement(name = "bi", namespace = "namespace...", type = ValueBinary.class)
})
protected List<Value> biOrAOrSOrB.....;
However if I change the server side class to be a single item instead of a list i.e. so the WSDL contains <choice> instead of <choice maxOccurs="unbounded" minOccurs="0">
then instead on the client side I get a variable for every possible choice option
@XmlElement(namespace = "namespace...")
protected ValueBinary bi;
@XmlElement(namespace = "namespace...")
protected ValueAnySimpleType a;
@XmlElement(namespace = "namespace...")
protected ValueString s;
@XmlElement(namespace = "namespace...")
protected ValueBoolean b;
etc, you get the general picture. Now since xs:choice allows only one of the items in the choice list, surely this second lot of code that is generated is incorrect, since I should still be getting just one variable ?
I've tried updating to the latest JAXB-RI & JAX-WS and it didn't make any difference.
Am I being dumb or is this a JAXB-RI bug ?
many thanks in advance. Owen
Upvotes: 0
Views: 225
Reputation: 21
ah if you bash your head against google for long enough you find the answer....
http://blog.bdoughan.com/2011/04/xml-schema-to-java-xsd-choice.html
Upvotes: 0