我希望這可以幫助一點,
以下爲恢復其使用Gson構建與Poster測試的網址是域名JSON對象的工作示例://端口項目名/服務/ REST/getjson?name = gopi
構建一個複雜的對象,只要你喜歡,最後轉換爲使用Gson的json。
@Path("rest")
public class RestImpl {
@GET
@Path("getjson")
@Produces("application/json")
public String restJson(@QueryParam("name") String name)
{
EmployeeList employeeList = new EmployeeList();
List<Employee> list = new ArrayList<Employee>();
Employee e = new Employee();
e.setName(name);
e.setCode("1234");
Address address = new Address();
address.setAddress("some Address");
e.setAddress(address);
list.add(e);
Employee e1 = new Employee();
e1.setName("shankar");
e1.setCode("54564");
Address address1 = new Address();
address.setAddress("Address ");
e1.setAddress(address);
list.add(e1);
employeeList.setEmplList(list);
Gson gson = new Gson();
System.out.println(gson.toJson(employeeList));
return gson.toJson(employeeList);
}
@GET
@Produces("text/html")
public String test()
{
return "SUCCESS";
}
}
PS:我不想給擡起頭,傑克遜之間的戰鬥VS GSON ;-)
我希望你會搜索SO或谷歌與你的異常.. HTTP:/ /stackoverflow.com/questions/9256112/no-message-body-writer-found-json-apache-cxf-restful-webservices – Sikorski 2012-08-09 13:27:36