Search code examples
javalistjaxbjaxb2

What is the default List implementation in Jaxb2, and how do I change it?


Does anyone know what the default implementation is for List instances in JaxB2?

Is there a way to change the implementation, and if so, what is it?


Solution

  • The default List implementation in JAXB 2 is java.util.ArrayList. When generating your model from an XML schema you can set the collectionType in an external bindings file to choose an alternate implementation:

    <jxb:bindings
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
        version="2.1">
    
        <jxb:bindings schemaLocation="customer.xsd">
            <jxb:bindings node="//xs:element[@name='customer']/xs:complexType/xs:sequence/xs:element[@name='phone-number']">
                <jxb:property collectionType="java.util.LinkedList"/>
            </jxb:bindings>
        </jxb:bindings>
    
    </jxb:bindings>
    

    For More Information