Apace CXF for REST application

I started to configure my first RESTful app using Apache CXF library and bumped into issue with JAX-RS binding. No matter how I tried to map my classes, I’ve still been getting this error in response instead of JSON data:

No message body writer has been found for response class ArrayList.

The solution was to add dependency on JSON mapping provider since Apache CXF does not include it. It can be XStream or Jackson, I used the last one.

Step 1.

Add dependency for org.codehaus.jackson:jackson-jaxrs to your project

Step 2.

Add JSON provider to Spring context configuration:

<beans xmlns="http://www.springframework.org/schema/beans"...>
...
    <jaxrs:server id="serviceId">
        <jaxrs:serviceBeans>
            <ref bean="myService"/>
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
        </jaxrs:providers>
    </jaxrs:server>
...
</beans>

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.