i'm attempting to translate some JAXB xjc.exe generated classes to Simple XML classes. i'm not sure how to annotate dynamic elements. for example, in the schema, i have:
<!-- Message Set Request/Response Pairs and contained requests -->
<xsd:element name="QBXMLMsgsRq">
<xsd:complexType>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="HostQueryRq" type="HostQueryRqType"/>
<xsd:element name="CompanyQueryRq" type="CompanyQueryRqType"/>
<xsd:element name="CompanyActivityQueryRq" type="CompanyActivityQueryRqType"/>
<!-- many more of these choices -->
</xsd:choice>
<xsd:attribute name="oldMessageSetID" type="STRTYPE"/>
<!-- some other attributes -->
</xsd:complexType>
</xsd:element>
which, when run through xjc.exe, generates the following annotation for the @XmlElement
@XmlElements({
@XmlElement(name = "HostQueryRq", type = HostQueryRqType.class),
@XmlElement(name = "CompanyQueryRq", type = CompanyQueryRqType.class),
@XmlElement(name = "CompanyActivityQueryRq", type = CompanyActivityQueryRqType.class),
//+ et al
})
protected List<Object> hostQueryRqOrCompanyQueryRqOrCompanyActivityQueryRq;
so how can i translate this JAXB structure to a SimpleXML annotated class structure?
the answer is to use ElementListUnion to identify the available choices for the List types. check here under "Collecting various types in a single list". example:
@Root
public class Example {
@ElementListUnion({
@ElementList(entry="int", type=Integer.class, inline=true),
@ElementList(entry="date", type=Date.class, inline=true),
@ElementList(entry="text", type=String.class, inline=true)
})
private List<Object> list;
}