JAXB - Binding element for a set instead of a list

Is there a way to get JAXB to generate a Collection instead of a List for a specific element?

For example, creating a book set for this xsd:

<xs:element name="Collection">
<xs:complexType>
  <xs:sequence>
    <xs:element name ="books">
       <xs:complexType>
          <xs:sequence>
            <xs:element name="book" type="bookType" minOccurs="1" maxOccurs="unbounded"/>
          </xs:sequence>
       </xs:complexType>
    </xs:element>
  </xs:sequence>

Using the following bindings.xml

<jxb:bindings schemaLocation="schema.xsd">
    <jxb:bindings node="//xs:element[@name='Shop']/xs:complexType/xs:sequence/xs:element[@name='books']">
        <jxb:property collectionType="java.util.HashSet" />
    </jxb:bindings>
</jxb:bindings>

A list of books with a concrete implementation of HashSet is generated:

List<Book> books = new HashSet<Book>();
+5
source share
1 answer

I don’t think that this can be done using special bindings, because according to the Configuring JAXB Bindings guide :

collectionType propertyCollectionType, . propertyCollectionType , , , java.util.List.

, , , xjc-. , , : JAXB RI

+6

All Articles