I need to generate an xml element that can have any "primitive type" as value (xsd: string, xsd: boolean, etc.). Examples:
<field xsi:type="xsd:string" name="aString">String Value</field> <field xsi:type="xsd:dateTime" name="aDate">2011-10-21</field> <field xsi:type="xsd:dateTime" name="aDateTime">2011-10-21T12:00:00</field> ...
So, I use this implementation, which forces JAXB to define xsi:type primitive type:
public class Field { @XmlAttribute private String name; @XmlElement Object value; }
and it works as expected, but all java.util.Date gets type xs:dateTime ...
Now I want to change the behavior of the marshaller ONLY when the 'value' object is an instance of java.util.Date to get these fields:
<field xsi:type="xsd:date" name="aDate">2011-10-21</field> <field xsi:type="xsd:dateTime" name="aDateTime">2011-10-21T12:00:00</field>
So, I am creating an adapter, but if I try this:
@XmlElement @XmlJavaTypeAdapter(DateAdapter.class) Object value;
The adapter must handle the java.lang.Object type
public class DateAdapter extends XmlAdapter<String, Object> {...}
But I do not want to lose JAXB marshalls for all other objects (Integer, Double, etc.) ...
Is there a way to install an adapter for a specific subtype of an element?