4

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

tun_eng
  • 133
  • 1
  • 3
  • 13
  • http://docs.jboss.org/resteasy/docs/2.3.3.Final/userguide/html_single/index.html#JAXB_Map – eiden Aug 28 '12 at 08:26
  • Did you try directly returning `Map`, instead of a `Response` object? – Flavio Aug 29 '12 at 07:25
  • this might help: https://community.jboss.org/thread/191022?_sscc=t – Andrei Sfat Aug 29 '12 at 07:30
  • @ Flavio : yes I tried to return directly Map instead of Response, but I had the same problem. – tun_eng Aug 30 '12 at 10:40
  • 1
    I **resolved** the problem in **Tomcat** by the modifications that I found in [this link](http://stackoverflow.com/questions/1900132/jax-rs-mapstring-string-to-json-without-the-overhead). The author wrote how he had recovered a map in JSON. **But I encounter always the same problem in JBOSS** – tun_eng Aug 30 '12 at 10:45
  • I have packaged the war and the jar that I had in an ear and deployed the ear in JBoss server. the problem has been resolved and I can now see the code JSON returned. Thanks to all :) – tun_eng Sep 03 '12 at 08:45
  • I think you may had been missing a JSON Resteasy provider in your classpath; you should package it with you war file. You could try setting this in your pom.xml file: http://search.maven.org/#artifactdetails%7Corg.jboss.resteasy%7Cresteasy-jackson-provider%7C2.0.1.GA%7Cjar – Fabio Kenji May 07 '13 at 21:57

1 Answers1

1

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.

yntelectual
  • 3,028
  • 18
  • 24