0

我正在开发一个模块,我在其中使用休息服务来获取数据。我没有得到如何使用杰克逊存储 JSON 并存储它也有 Queryparam。任何帮助都非常感谢,因为我是新手。我正在尝试在 extjs 无限网格中进行服务器端过滤,该网格将以下请求发送到休息服务。

当页面第一次加载时,它会发送:

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 中,然后将其发送到数据库以检索数据。在休息方面,我写了这样的东西:

@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
}

我收到以下错误:

The following warnings have been detected with resource and/or provider classes: WARNING: A HTTP GET method, public abstract javax.ws.rs.core.Response com.xx.xx.xx.xxxxx (com.xx.xx.xx.xx.json.FilterJsonToJava ,java.lang.String,java.lang.String,java.lang.String), should not consume any entity.  

com.xx.xx.xx.xx.json.FilterJsonToJava, and Java type class com.xx.xx.xx.FilterJsonToJava, and MIME media type application/octet-stream was not found  

[11/6/13 17:46:54:065] 0000001c ContainerRequ E   The registered message body readers compatible with the MIME media type are:

application/octet-stream  
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider  com.sun.jersey.core.impl.provider.entity.FileProvider   com.sun.jersey.core.impl.provider.entity.InputStreamProvider   com.sun.jersey.core.impl.provider.entity.DataSourceProvider com.sun.jersey.core.impl.provider.entity.RenderedImageProvider */* -> com.sun.jersey.core.impl.provider.entity.FormProvider ...
4

1 回答 1

0

你应该尝试这样做:

Response getallGridData(@QueryParam("filter") String filterparam, ...) { 

ObjectMapper mapper = new ObjectMapper();
Filter yourObject = mapper.readValue(filterparam, Filter.class);

}

就是这样,因为您的有效负载在查询参数中。当有有效负载时,与 POST 请求一样注入的对象。

于 2013-11-07T10:25:41.233 回答