有没有办法让JAXB为一个已定义的元素生成Collection Set而不是List呢?
例如,为这个xsd生成一组书籍的Set:
当使用以下的bindings.xml文件时:
生成一个包含具体 HashSet 实现的书籍列表:
例如,为这个xsd生成一组书籍的Set:
<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>
当使用以下的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>
生成一个包含具体 HashSet 实现的书籍列表:
List<Book> books = new HashSet<Book>();