0

我有一个复杂的 Employee POJO 类,它有 Name、id、salary、dept 和 Address(vector type) 字段。我使用 jersey restful web 服务生成了 json。但是输出的 json 不包括某些 pojo 字段,例如数据类型为向量的地址。POJO 类中的所有字段都有 getter 和 setter。

为什么某些字段不属于生成的 JSON 的任何具体原因?

//使用下面的代码生成JSON

     @Path("/employeedDetails")
             @GET
             @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})         
             public EmployeedBean getDetails(@QueryParam("Id") String Id, 
                   @Context HttpServletRequest servletRequest) {
 Employee e1 = new Employee();

// 设置所有 Name、id、salary、dept 和 Address return e1; }

4

1 回答 1

0

You are missing code. Can you post what you are returning? If you are returning an array (such as a Java List object), you'll want to wrap that inside another POJO class. I was having the same issue (see RESTful POJO -> JSON mapping not picking up new fields) and this was what was causing it, since the returned JSON was starting with brackets [] instead of {} and therefore JavaScript wasn't parsing it properly. Returning a single object instead of a List fixed the issue.

于 2013-08-01T01:14:00.930 回答