title: XmlJavaTypeAdapter with CXF and JAX-WS
body: <p>I have a class X which is used in a Service interface of a Web service built with <strong>Apache CXF</strong> and <strong>JAX-WS</strong>. This class X has no default constructor and I would like to avoid this default constructor. I was wondering whether I can use the @XmlJavaTypeAdapter annotation as a solution. </p>
  
  <p>The methods from the ClassXService:</p>
  
  <pre><code>@WebMethod
  @XmlJavaTypeAdapter(ClassXAdapter.class)
  public void myMethod(ClassX arg0);
  
  @WebMethod
  @XmlJavaTypeAdapter(ClassXAdapter.class)
  public ClassX myMethod2();
  </code></pre>
  
  <p>The adapter extends XmlAdapter and defines correctly the marshal and unmarshal methods.</p>
  
  <p>However, with or without using the XmlJavaTypeAdapter annotation, I am always getting the same error:</p>
  
  <pre><code>Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException
      at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:292)
      at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
      at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:438)
      at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:682)
      at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:501)
      at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:241)
      at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:202)
      at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
      at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:157)
      at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:202)
      at my.package.Main.main(Main.java:35)    
  Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
      my.package.ClassX does not have a no-arg default constructor.
          this problem is related to the following location:
              at my.package.ClassX
              at private my.package.ClassX my.package.jaxws_asm.MyMethod.arg0
              at my.package.jaxws_asm.MyMethod2
  at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
  at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)
  at com.sun.xml.bind.v2.runtime.JAXBContextImpl.&lt;init&gt;(JAXBContextImpl.java:302)
  at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140)
  at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
  at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:616)
  at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:222)
  at javax.xml.bind.ContextFinder.find(ContextFinder.java:383)
  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:594)
  at org.apache.cxf.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:258)
  at org.apache.cxf.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:167)
  at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:418)
  at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:290)
  ... 10 more
  </code></pre>
  
  <p>Is it not possible to use an adapter to avoid to provide a default no-arg constructor? If yes, does someone has an idea why I get an exception even when the XmlJavaTypeAdapter annotation is used?</p>