title: JAXB: XmlAdapter for List<Object> items
body: <p>Does anybody know how to attach custom <code>XmlAdapter</code> to objects contained in heterogenous list (like List)?
  For example - suppose we have a container class with a list of miscelaneous objects:</p>
  
  <pre><code>@XmlRootElement(name = "container")
  public class Container {
      private List&lt;Object&gt; values = new ArrayList&lt;Object&gt;();
  
      @XmlElement(name = "value")
      public List&lt;Object&gt; getValues() {
          return values;
      }
  
      public void setValues(List&lt;Object&gt; values) {
          this.values = values;
      }   
  }
  </code></pre>
  
  <p>If we put <code>String</code>-s, <code>Integer</code>-s and so on they will be mapped by default. Now suppose we want to put a custom object:</p>
  
  <pre><code>public class MyObject {
      //some properties go here   
  }
  </code></pre>
  
  <p>The obvious solution is to write a custom adapter:</p>
  
  <pre><code>public class MyObjectAdapter extends XmlAdapter&lt;String, MyObject&gt; {
      //marshalling/unmarshalling
  }
  </code></pre>
  
  <p>But unfortunately it doesn't work with package-level <code>@XmlJavaTypeAdapter</code> - adapter just never called so marhalling fails.
  And I can't apply it to <code>getValues()</code> directly because there can be other types of objects.
  <code>@XmlJavaTypeAdapter</code> only works if I have a field of MyObject type in Container (also with package-level annotaton):</p>
  
  <pre><code>public class Container {
      private MyObject myObject;
  }
  </code></pre>
  
  <p>But this is not what I want - I want a list of arbitrary objects. I'm using standard Sun's JAXB implementation:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
      &lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt;
      &lt;version&gt;2.2.3-1&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Any ideas how to do the mapping?</p>
  
  <p>P.S.: One small clarification - I'd like to avoid annotating <code>MyObject</code> with JAXB annotations. It may be a class from third-party library which is not under my control. So any changes should be outside of <code>MyObject</code>.</p>