如何使用Jackson将JSON存储到POJO中
我正在开发一个模块,使用rest服务获取数据。我不知道如何使用Jackson存储JSON并存储它,因为它也有Queryparam。非常感谢您的帮助,因为我是新手。我正在尝试在extjs infinte网格中进行服务器端过滤,该网格正在向rest服务发送以下请求 首次加载页面时,它会发送:如何使用Jackson将JSON存储到POJO中,json,rest,Json,Rest,我正在开发一个模块,使用rest服务获取数据。我不知道如何使用Jackson存储JSON并存储它,因为它也有Queryparam。非常感谢您的帮助,因为我是新手。我正在尝试在extjs infinte网格中进行服务器端过滤,该网格正在向rest服务发送以下请求 首次加载页面时,它会发送: http://myhost/mycontext/rest/populateGrid?_dc=9999999999999&page=1&start=0&limit=500 选择“名称和位
http://myhost/mycontext/rest/populateGrid?_dc=9999999999999&page=1&start=0&limit=500
选择“名称和位置过滤器”时,会发送:
http://myhost/mycontext/rest/populateGrid?_dc=9999999999999&filter=[{"type":"string","value":"Tom","field":"name"},{"type":"string","value":"London","field":"Location"}]&page=1&start=0&limit=500
我试图将其保存在POJO中,然后将其发送到数据库以检索数据。在rest端,我写了如下内容:
@Provider
@Path("/rest")
public interface restAccessPoint {
@GET
@Path("/populateGrid")
@Produces({MediaType.APPLICATION_JSON})
public Response getallGridData(FilterJsonToJava filterparam,@QueryParam("page") String page,@QueryParam("start") String start,@QueryParam("limit") String limit);
}
public class FilterJsonToJava {
@JsonProperty(value ="filter")
private List<Filter> data;
.. getter and setter below
}
public class Filter {
@JsonProperty("type")
private String type;
@JsonProperty("value")
private String value;
@JsonProperty("field")
private String field;
...getter and setters below
}
您应该尝试这样做:
Response getallGridData(@QueryParam("filter") String filterparam, ...) {
ObjectMapper mapper = new ObjectMapper();
Filter yourObject = mapper.readValue(filterparam, Filter.class);
}
这就是方法,因为您的负载在查询参数中。当存在有效负载时,使用POST请求按原样注入的对象
Response getallGridData(@QueryParam("filter") String filterparam, ...) {
ObjectMapper mapper = new ObjectMapper();
Filter yourObject = mapper.readValue(filterparam, Filter.class);
}