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

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 to a Tomcat server. I use RESTeasy as a frame. When I try to access the service, I come across this:

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

I did not understand what the problem was.

Thank you in advance

+4
source share
1 answer

How do you deploy your application? Which application server are you using? What version of RestEasy? What RestEasy configuration did you specify (in web.xml or the Application class)? Resteasy relies on providers to serialize / deserialize objects. These providers must be contained in the class path of your JAX-RS application. Depending on your build, application packaging, and runtime, these providers may not be available. In addition, provider discovery can be configured, for example. automatically detect all drivers in the classpath or use only those that are explicitly specified in conf. Commonly used providers with application / json capabilities are resteasy-jackson-provider, resteasy-jettison-provider. Make sure at least one of them is available in your class path.

0
source

All Articles