注意!你可能不会对决定施加压力,只要告诉我:我应该考虑哪个方向!
所以,我们有一个非常简单的服务:
@GET
@Path("/search")
@Consumes(MediaType.APPLICATION_JSON)
public Response getSubscriber(@QueryParam("data") SubscriberSearchFormData data){
System.out.println(data);
List <SubscrEntity> results = null //list of results
return Response.ok(results).build();
}
使用的类SubscriberSearchFormData:
public class SubscriberSearchFormData {
private String name;
private String street;
private Integer contractNumber;
public static SubscriberSearchFormData fromString(String jsonRepresentation) throws Exception {
System.out.println("WE ARE HERE");
ObjectMapper mapper = new ObjectMapper(); // Jackson's JSON marshaller
SubscriberSearchFormData obj = null;
try {
obj = mapper.readValue(decoded, SubscriberSearchFormData.class);
} catch (IOException e) {
throw new Exception("Wrong JSON parameters!");
}
return obj;
}
//all getters and setters
}
根据这个想法,JSON应该由方法fromString()
自动解析为SubscriberSearchFormData类的对象。我们将继续与他合作。但是当我调用服务时:
localhost:8080/application/rest/catalog/subscriber/search?data={
"name":"bbb",
"street":"eee",
"contractNumber":5
}
由于错误导致一切都失败:
11:24:04,050 WARN [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-3) RESTEASY002130:
Failed to parse request.: javax.ws.rs.core.UriBuilderException: RESTEASY003330:
Failed to create URI: http://localhost:8080/application/rest/catalog/subscriber/search?data={%20%22name%22:%22bbb%22,%20%22street%22:%22eee%22,%20%22contractNumber%22:%225%22}
与此同时,System.out.println ("WE ARE HERE");
甚至没有被调用。它甚至在致电fromString ();
我第二天挖掘它并且无法解决。
答案 0 :(得分:1)
看起来您的URI无法正确解析,因为它包含非法字符;这个问题在这里得到解决: IllegalArgumentException caught when parsing URL with JSON String
这也很有用:http://docs.jboss.org/resteasy/docs/3.0.7.Final/userguide/html_single/index.html#_QueryParam
相关联