highsource / jaxb2-basics

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

multiple choice element that implement thesame base class #79

Open bolemeus opened 7 years ago

bolemeus commented 7 years ago

I have a question.

I've got the following xsd element

<xsd:complexType name="Types">
    <xsd:sequence>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="TypeA" type="TypeA"/>
            <xsd:element name="TypeB" type="TypeB"/>
            <xsd:element name="TypeC" type="TypeC"/>
        </xsd:choice>
    </xsd:sequence>
</xsd:complexType>

and in my bindings file

<jaxb:bindings schemaLocation="types/typeA-v2.xsd" node="/xsd:schema">
    ...
    <jaxb:bindings node="xsd:complexType[@name='TypeA']">
        <inheritance:extends>nl.jaxb2-basics.example.dto.AbstractType</inheritance:extends>
    </jaxb:bindings>
</jaxb:bindings>

<jaxb:bindings schemaLocation="types/typeB-v1.xsd" node="/xsd:schema">
    ...
    <jaxb:bindings node="xsd:complexType[@name='TypeB']">
        <inheritance:extends>nl.jaxb2-basics.example.dto.AbstractType</inheritance:extends>
    </jaxb:bindings>
</jaxb:bindings>

<jaxb:bindings schemaLocation="types/typeC-v1.xsd" node="/xsd:schema">
    ...
    <jaxb:bindings node="xsd:complexType[@name='TypeC']">
        <inheritance:extends>nl.jaxb2-basics.example.dto.AbstractType</inheritance:extends>
    </jaxb:bindings>
</jaxb:bindings>

The generated code now creates a List of Serializables, which is not really what I want. The Simplify plugin looks promising, but would give me three seperate lists.

Is there a way for me to make it a generated list of AbstractTypes using the inheritance plugin.

PS: I simplified the code a bit.

manstis commented 3 years ago

This type of construct works for me

<jaxb:bindings node="x-path-to-where-Types-is-used">
  <jaxb:property>
    <jaxb:baseType name="nl.jaxb2-basics.example.dto.AbstractType"/>
  </jaxb:property>
</jaxb:bindings>