我正在使用 Apache CXF 来制作一个简单的宁静应用程序。我有一个客户端类,它将一个 JSON 对象发布到服务器,服务器在一些操作后返回一个 JSON。但是当我执行我得到的代码时
"org.apache.cxf.interceptor.Fault: .No message body writer has been found for class:
class org.codehaus.jettison.json.JSONObject, ContentType : application/json."
我的客户代码:
public class Client {
public static void main(String[] args) {
try{
URI uri = new URI("http://localhost:8022/RestDemo");
WebClient client = WebClient.create(uri);
String ret = client.path("rest").path("server").path("welcome").accept(MediaType.TEXT_PLAIN).get(String.class);
System.out.println(ret);
JSONObject json = new JSONObject();
json.put("name", "ronaldo");
json = client.path("rest").path("server").path("op").type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(json, JSONObject.class);
System.out.println(json);
System.out.println(json.has("reverse")?json.getString("reverse"):"dont have");
}catch(Exception e){
System.out.println("e"+e.getLocalizedMessage());
e.printStackTrace();
}
}
}
请帮忙。