Search code examples
javajaxbcxf

JAXB Bindings for code generation using CXF


I am generating Java stubs from a WSDL using CXF codegen plugin and jaxb. In the bindings, I have specified that one particular object in one of the stubs has to be a String object even though the XSD has specified it as an integer.

The binding:

<jxb:bindings schemaLocation="../../../../../WSDL_Package/ABC/ABC_1.xsd">
        <jxb:bindings node="//xs:complexType[@name='TypeI']//xs:sequence//xs:element[@name='number']">
            <xjc:javaType name="java.lang.String" adapter="javax.xml.bind.annotation.adapters.XmlAdapter" />
        </jxb:bindings>
    </jxb:bindings>

But on using the stubs in my project, I get the exception

INFO: failed to create a new instance of class javax.xml.bind.annotation.adapters.XmlAdapter java.lang.InstantiationException

Can someone help with resolving this issue?


Solution

  • Because javax.xml.bind.annotation.adapters.XmlAdapter is an abstract class and cannot be instantiated. You must implement your adapter.

    public final class MyAdapter extends XmlAdapter<Type1,Type2> { ... }