user1491636
user1491636

Reputation: 2446

CXF - No message body reader

I've tried many of the solutions in this forum to address this issue with no luck. I am using Apache CXF (v.2.5.11) and I need to post some Json to a REST endpoint and have the data unmarshaled to a Java object (e.g. Map).

When I post the request I get an internal server error with

org.apache.cxf.jaxrs.utils.JAXRSUtils readFromMessageBody
WARNING: No message body reader has been found for request class Map, ContentType : application/json.

I tried the solution here but with class com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider and maven artifact jackson-jaxrs-json-provider (version 2.5.4). No luck.

My endpoint is defined as such:

@POST
@Path("/test")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response test(Map<String, Object> test) {
    ...
}

UPDATE

So I've figured out that if I go back to an old codehaus version of the JacksonJsonProvider, marshalling works fine:

Spring context:

<jaxrs:providers>           
    <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>      
</jaxrs:providers>

With dependency:

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-jaxrs</artifactId>
    <version>1.9.0</version>
</dependency>

So I guess something has changed in the fasterxml 2.4+ version.

Upvotes: 1

Views: 8408

Answers (1)

monsIgnore
monsIgnore

Reputation: 91

I encountered the same issue.

According to http://osdir.com/ml/users-cxf-apache/2013-06/msg00212.html there was an error in cxf prior to 2.7.6

So try upgrading to cxf 2.7.6 (or newer) and your code should be working again.

Upvotes: 1

Related Questions