2

我知道我可以解决这个问题,但是与将参数拉出参数映射(应根据 javadoc 解码)相比,如果使用带注释的查询参数,行为会有所不同,这似乎很奇怪。这是一个错误,还是只是一个怪癖?

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getAssets(@Context UriInfo info, @QueryParam("q") String searchQuery) {

    // The request URI is http://myhost.com/appRoot?q=foo+bar%20baz
    // At this point seachQuery="foo bar baz"
    // The + has been decoded (along with any % encoded characters)

    // Here searchQuery2="foo+bar baz", the '+' has not been decoded
    // but the %20 has been
    MultivaluedMap<String, String> params = info.getQueryParameters();
    String searchQuery2 = params.get("q").get(0);
4

1 回答 1

2

根据 Javadocs,UrlInfo.getQueryParameters仅“对参数名称和值中的转义八位字节序列进行解码”。

另一方面,QueryParam Javadocs 声明“值是URL 解码的,除非使用Encoded注释禁用它”。

所以,回答你的问题,它看起来像是一个规范决定。

无论如何,也许您应该在JAX-RS 邮件列表上提出该讨论。

于 2015-04-23T13:56:56.670 回答