Changing the Java class associated with an XML type

wsdl2java-maven-plugin uses the default mappings between XML types and Java classes determined by the configured typeMappingVersion. However, there may be situations where you might want to represent a given XML type using a Java type other than the one determined by the default mapping. E.g. you might want xs:base64Binary to be represented by java.activation.DataHandler instead of the default byte[]. This can be achieved using the javaXmlTypeMappings parameter as shown in the following sample:

<javaXmlTypeMappings>
    <javaXmlTypeMapping>
        <xmlType>{http://www.w3.org/2001/XMLSchema}base64Binary</xmlType>
        <javaType>javax.activation.DataHandler</javaType>
    </javaXmlTypeMapping>
</javaXmlTypeMappings>

Note the unusual way to represent the QName of the XML type (which the plugin uses to work around a restriction in Maven).

This feature is similar to the java-xml-type-mapping element in the JAX-RPC mapping file defined by the Enterprise Web Services 1.1 specification.

In addition to specifying a javaXmlTypeMapping, you also need to make sure that a corresponding type mapping is registered at runtime. This is typically done by adding an appropriate typeMapping element in the relevant WSDD file.

Example: consuming an MTOM enabled Web service

By default stubs generated using wsdl2java don't support MTOM, although Axis has the necessary serializers/deserializers that recognize xop:Include elements and that use java.activation.DataHandler to represent the binary data in Java. To enable them, map the xs:base64Binary type to java.activation.DataHandler as shown above and set up a client-config.wsdd file with the following type mapping:

<typeMapping languageSpecificType="java:javax.activation.DataHandler" qname="xs:base64Binary"
             deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory"
             serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory" 
             encodingStyle=""/>