title: Binding JiBX to a JAXB POJO that has a List containing multiple types of objects?
body: <p><b>Question</b>: How do I bind JiBX to a JAXB POJO that has a List containing multiple types of objects?</p>
  
  <p><b>Background</b>: We are attempting to migrate from JAXB to JiBX for XML serialization in order to increase performance. However, we cannot change the POJOs generated from JAXB as they are provided by our customer. I am having problems on how to adjust my <code>binding.xml</code> to work with <code>List</code> types generated from JAXB (no setter for JAXB generated lists).</p>
  
  <p>Here is the XSD snippet</p>
  
  <pre><code>&lt;xs:element name="contact_plan"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="header" maxOccurs="1"/&gt;
              &lt;xs:choice maxOccurs="unbounded"&gt;
                  &lt;xs:element ref="ctp:asc_node" maxOccurs="unbounded"/&gt;
                  &lt;xs:element ref="ctp:desc_node" maxOccurs="unbounded"/&gt;
                  &lt;xs:element ref="ctp:exit_umbra" maxOccurs="unbounded"/&gt;
                  &lt;xs:element ref="ctp:enter_umbra" maxOccurs="unbounded"/&gt;
                  &lt;xs:element ref="ctp:contact" maxOccurs="unbounded"/&gt;
              &lt;/xs:choice&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>JAXB Generated Code</p>
  
  <pre><code>/**
   * Gets the value of the a property.
   * 
   * &lt;p&gt;
   * This accessor method returns a reference to the live list,
   * not a snapshot. Therefore any modification you make to the
   * returned list will be present inside the JAXB object.
   * This is why there is not a &lt;CODE&gt;set&lt;/CODE&gt; method for the a property.
   * 
   * &lt;p&gt;
   * For example, to add a new item, do as follows:
   * &lt;pre&gt;
   *    getAs().add(newItem);
   * &lt;/pre&gt;
   * 
   * 
   * &lt;p&gt;
   * Objects of the following type(s) are allowed in the list
   * {@link D }
   * {@link Ex }
   * {@link A }
   * {@link En }
   * {@link C }
   * 
   * 
   */
  public List&lt;Object&gt; getAs() {
      if (as == null) {
          as = new ArrayList&lt;Object&gt;();
      }
      return this.as;
  }
  </code></pre>
  
  <p>JiBX wants to do this in the binding:</p>
  
  <pre><code>&lt;mapping class="c" name="c"&gt;
    &lt;structure type="c" get-method="getHeader" set-method="setHeader"/&gt;
    &lt;collection get-method="getAs" set-method="setAs"
                create-type="java.util.ArrayList"&gt;
    &lt;/collection&gt;
  &lt;/mapping&gt;
  </code></pre>
  
  <p>The <code>setAs</code> method doesn't exist on the generated JAXB POJO. Thus the exception <code>Error: Nonstatic set-method setAs with argument of appropriate type not found in class.</code> is thrown and I cannot create a binding. The JiBX generated POJOs also have separate lists for each type instead of one list for all of them.</p>
  
  <p><b>What I've Tried</b>: </p>
  
  <ol>
  <li>I explored the option of creating my own Marshaller and Unmarshaller for the plan xsd element type. However, then (as far as I know) I would also have to write custom marshallers / unmarshallers for each of the types contained in the list (&lt;--<strong>Is this assumption correct?</strong>). I would prefer to avoid this if possible.</li>
  <li>I've explored trying to adjust the <code>binding.xml</code> to try and use the the marshallers for the types contained in the list however I don't think there is a way to do that with the binding.xml only.</li>
  </ol>
  
  <p>If you have any helpful experience or suggestions that would help with my problem please advise. Thank you for your time and please let me know if I can clarify further.</p>