Java Jersey Jettison Message Body Reader Exception

安稳与你 提交于 2019-12-18 06:54:10

问题


I am a complete beginner at REST services but I need to access some information via REST from a web site. The service has some sample code to show how to login that I have used. The sample code uses Jettison as a JSON parser but when I try to run the following code snippet 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 fails 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 should need to add any "message body readers" to handle the response? Or do I need to add or do anything obvious to parse the response? Thanks.


回答1:


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



来源:https://stackoverflow.com/questions/7777661/java-jersey-jettison-message-body-reader-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!