Body Message exception exception

I am a complete newbie to REST services, but I need to access some information through REST from a website. The service has sample code to show how to log in to the system I used. The sample code uses Jettison as a JSON parser, but when I try to execute the following code fragment, I get an exception:

JSONObject post = baseResource.path("login") .queryParam("service", "ABC").queryParam("auth", authParam) .accept(MediaType.APPLICATION_JSON_TYPE).post(JSONObject.class); 

baseResourse is a WebResource object. The code does not work with the following exception:

 Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class org.codehaus.jettison.json.JSONObject, and Java type class org.codehaus.jettison.json.JSONObject, and MIME media type application/json; character=utf-8 was not found 

The sample code does not suggest that I will need to add β€œmessage body readers” to handle the response? Or do I need to add or do something obvious to analyze the answer? Thanks.

+4
source share
1 answer

You need to include the jersey-json module in your class. See http://jersey.java.net/nonav/documentation/latest/chapter_deps.html#d4e1817

+6
source

All Articles