【发布时间】:2014-05-21 19:21:30
【问题描述】:
您好,我正在尝试使用 Jersey 从一个简单的方法中返回 Json
HelloWorldService.class
@Path("/hello")
public class HelloWorldService {
@GET
@Path("/empdetail/{id}")
@Produces(MediaType.APPLICATION_JSON)
public EmpDetailsVo getEmpDetails(@PathParam("id") String id){
EmpDetailsVo details = new EmpDetailsVo();
details.empId="1202";
details.empName="Akhi";
details.empAddress="123 Main St. Newark PA 19121";
return details;
}
}
EmpDetailsVo 类具有 empId、name 和 address 的 getter 和 setter。
当我尝试运行这个网址时:
http://localhost:8080/jerseyRest/rest/hello/empdetail/1202
我得到了 Http 状态500。
在控制台上我看到一个错误:
SEVERE: A message body writer for Java class jerseyRest.EmpDetailsVo, and Java type class jerseyRest.EmpDetailsVo, and MIME media type application/json was not found
和
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class jerseyRest.EmpDetailsVo, and Java type class jerseyRest.EmpDetailsVo, and MIME media type application/json was not found
有人可以帮忙吗。
【问题讨论】: