我希望这可以帮助一点,
以下为恢复其使用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