[英]POJO attributes is returning as a Array for JSON in JAX-RS
I have a java web maven project with JAX-RS using resteasy version 2.2.1.GA implementation. 我有一个使用resteasy 2.2.1.GA版本的JAX-RS的Java Web Maven项目。 All JAX-RS resources on the project produces y consumes application/json.
项目上所有的JAX-RS资源产生y都消耗application / json。 My problem is that when I returning a single POJO, even an array of this, only serialize the values of the attributes.
我的问题是,当我返回单个POJO时,即使是该数组的数组,也只能序列化属性的值。
Example: 例:
Given the following classes: 给定以下类别:
public class Pojo {
private Integer attr1;
private String attr2;
// GETTERs and SETTERs
}
@Path("pojos")
@Consumes("application/json")
@Produces("application/json")
public class PojoResource {
@GET
public Response list() {
List<Pojo> listResult = new ArrayList<>();
Pojo pojo = new Pojo();
pojo.setAttr1(1);
pojo.setAttr2("asdf");
listResult.add(pojo);
return Response.ok().entity(listResult).build();
}
}
If I do a GET request to /pojos, the result for the example above is [[1, "asdf"]]
, instead of [{"attr1":1,"attr2":"asdf"}]
如果我对/ pojos进行GET请求,则以上示例的结果为
[[1, "asdf"]]
,而不是[{"attr1":1,"attr2":"asdf"}]
I don't know if a need to write a specific Provider. 我不知道是否需要编写特定的提供程序。 My project configuration is similar to this .
我的项目配置与此类似。
我意识到我的错误是,层模型中的数据恢复是作为对象的向量,并在不进行处理的情况下返回该值(创建表示数据的POJO)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.