Is there a way to make JAXB generate the Collection Set instead of List for an defined element?
For example generating a Set of books 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>
When 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 concret HashSet implementation is generated:
List<Book> books = new HashSet<Book>();
JAXB is an XML-to-Java binding technology that enables transformation between schema and Java objects and between XML instance documents and Java object instances. JAXB technology consists of a runtime API and accompanying tools that simplify access to XML documents.
XJC is a Java SE tool that compiles an XML schema file into fully annotated Java classes. It is distributed within the JDK package and is located at /bin/xjc path.
xjb extension to resolve any conflicts in the WSDL or schema. For example if two elements have the same name and you want to distinguish between them you can rename one by specifying it the bindings file.
choiceContentProperty can be either true, false, 1, or 0. The default value is false.
I don't think it can be done with a custom binding, because according to the guide on Customizing JAXB Bindings:
collectionType
defines the customization valuepropertyCollectionType
, which is the collection type for the property.propertyCollectionType
if specified, can be either indexed or any fully-qualified class name that implementsjava.util.List
.
However, it might be possible to do this if you wrote your own xjc plugin. Take a look at the following article to see how: Writing a plug-in for the JAXB RI is really easy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With