title: JAXB - Set an XmlAdapter only for an specific sub type of an element?
body: <p>I have to generate a xml element  that can have as value any "primitive type" (xsd:string, xsd:boolean, etc). Examples:</p>
  
  <pre><code>&lt;field xsi:type="xsd:string" name="aString"&gt;String Value&lt;/field&gt;
  &lt;field xsi:type="xsd:dateTime" name="aDate"&gt;2011-10-21&lt;/field&gt;
  &lt;field xsi:type="xsd:dateTime" name="aDateTime"&gt;2011-10-21T12:00:00&lt;/field&gt;
  ...
  </code></pre>
  
  <p>So, I use this implementation that makes JAXB decide the <code>xsi:type</code> of the primitive type:</p>
  
  <pre><code>public class Field {
      @XmlAttribute
      private String name;
  
      @XmlElement
      Object value;
  }
  </code></pre>
  
  <p>and it is working as expected but all the java.util.Date gets the type <code>xs:dateTime</code> ... </p>
  
  <p>Now I want to change the behavior of the marshaller ONLY when the 'value' object is an instance of java.util.Date to obtains fields like this:</p>
  
  <pre><code>&lt;field xsi:type="xsd:date" name="aDate"&gt;2011-10-21&lt;/field&gt;
  &lt;field xsi:type="xsd:dateTime" name="aDateTime"&gt;2011-10-21T12:00:00&lt;/field&gt;
  </code></pre>
  
  <p>So I create an adapter, but if I try this:</p>
  
  <pre><code>@XmlElement
  @XmlJavaTypeAdapter(DateAdapter.class)
  Object value;
  </code></pre>
  
  <p>The adapter must handles a java.lang.Object type</p>
  
  <pre><code>public class DateAdapter extends XmlAdapter&lt;String, Object&gt; {...}
  </code></pre>
  
  <p>But I do not want to loose the JAXB marshallers for all the others objects (Integer, Double, etc) ... </p>
  
  <p>there is a way to set an adapter for a specific subtype of an element?</p>