4
votes

I have this REST service that returns JSON code :

@GET
@Path("/mypath")
@Produces(MediaType.APPLICATION_JSON)
public Response getS() {
    Map<String, String> map = new LinkedHashMap<String, String>();

    map.put(key1, val1);
    map.put(key2, val2);

    return Response.ok(map, MediaType.APPLICATION_JSON).build();
}

This service is deployed in a Tomcat server. I am using RESTeasy as framework. When trying to access the service, I encounter this:

Could not find MessageBodyWriter for response object of type: java.util.LinkedHashMap of media type: application/json.

I didn't understand what is the problem.

Thanks in advance

1
Did you try directly returning Map<String, String>, instead of a Response object?Flavio
@ Flavio : yes I tried to return directly Map<String, String> instead of Response, but I had the same problem.tun_eng
I resolved the problem in Tomcat by the modifications that I found in this link. The author wrote how he had recovered a map in JSON. But I encounter always the same problem in JBOSStun_eng

1 Answers

0
votes

How do you deploy your application? What application server do you use? What version of RestEasy? What RestEasy configuration have you specified(in web.xml or Application class)? Resteasy relies on providers for serialization/deserialization of objects. These providers need to contained in the classpath of your JAX-RS application. Depending on your build, application packaging and runtime environment these providers might be missing. Furthermore, discovery of providres can be configured, e.g. automatically discover all privoders in classpath, or only use those explicitly mentioned in conf. Commonly used providers with application/json capabilities are resteasy-jackson-provider, resteasy-jettison-provider. Verify that at least one of these is available in your classpath.