title: How do I get a CXF client to understand a List?
body: <p>I'm using Apache CXF for my restful web services. I have a service defined by an interface that returns a list of my bean.</p>
  
  <pre><code>@Path("/")
  @Produces("application/xml")
  public interface MyService {
  
    @GET
    @Path("/test")
    public List&lt;MyBean&gt; getBeans() throws IOException;
  
  }
  </code></pre>
  
  <p>..and the service implementation is as such;</p>
  
  <pre><code>public class MyServiceImpl implements MyService {
    public List&lt;MyBean&gt; getBeans() {
       ArrayList&lt;MyBean&gt; beans = new ArrayList&lt;MyBean&gt;();
       beans.add(new MyBean("foo", "bar");
       return beans;
    }
  }
  </code></pre>
  
  <p>This is deployed on my server and works fine. I can hit the service in my browser and get the result I'd expect. The problem is when I try to get a CXF client to call the service.</p>
  
  <p>In my client app I declare a client with the following spring config;</p>
  
  <pre><code>  &lt;jaxrs:client id="myClient" inheritHeaders="true"
                   address="myhost/test"
                   serviceClass="com.example.MyService"&gt;
       &lt;jaxrs:headers&gt;
         &lt;entry key="Accept" value="application/xml"/&gt;
       &lt;/jaxrs:headers&gt;
       &lt;jaxrs:providers&gt;
         &lt;ref bean="myJaxbXmlProvider"/&gt;
         &lt;ref bean="myJsonProvider"/&gt;
       &lt;/jaxrs:providers&gt;  
     &lt;/jaxrs:client&gt;
  
     &lt;bean id="myJaxbXmlProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"&gt;
       &lt;property name="jaxbElementClassMap" ref="myElementClassMap"/&gt;
     &lt;/bean&gt;
     &lt;bean id="myJsonProvider" class="org.apache.cxf.jaxrs.provider.JSONProvider"&gt;
       &lt;property name="jaxbElementClassMap" ref="myElementClassMap"/&gt;
     &lt;/bean&gt;
     &lt;util:map id="myElementClassMap"&gt;
       &lt;entry key="com.example.MyBean" value="bean"/&gt;
     &lt;/util:map&gt;
  </code></pre>
  
  <p>When the client is invoked I get this stacktrace;</p>
  
  <blockquote>
    <p>org.apache.cxf.jaxrs.client.ClientWebApplicationException:
    .Problem with reading the response
    message, class : interface
    java.util.List, ContentType :
    application/xml.<br>
    ....<br>
    Caused by:
    javax.ws.rs.WebApplicationException:
    java.lang.ClassCastException:
    com.example.MyBean
    cannot be cast to
    org.apache.cxf.jaxrs.provider.AbstractJAXBProvider$CollectionWrapper</p>
  </blockquote>
  
  <p>Any ideas?</p>