Search code examples
javajaxbmarshallingunmarshallingxjc

Generate java class with @XmlJavaTypeAdapter from scheme


I have xsd schema and my classes are generated from that schema.

I need XmlAdapter for correct marshaling/unmarshalling of some types. I created such adapter (e.g MyAdapter), but I can't just add it via @XmlJavaTypeAdapter(MyAdapter.class) because my classes are generated from the scheme.

Is it possible to generate class from scheme with adapter defined ?

e.g I have scheme - > I want

@XmlType(name = "someName")
@XmlEnum
@XmlJavaTypeAdapter(MyAdapter.class)
public enum MyGeneratedClass {
   // ...
}

XJC is used to create Java classes from scheme.


Solution

  • Try to use <xs:annotation>

    For instance :

    <xs:simpleType name="myType">
        <xs:annotation>
           <xs:appinfo>
            <xjc:javaType name="com.seriouscompany.seriousproduct.MyType"
              adapter="com.seriouscompany.seriousproduct.MyAdapter" /> 
           </xs:appinfo>
        </xs:annotation>
        ....
    

    This should help.