Search code examples
javajax-rsjersey-2.0jersey-client

In Jersey 2, why was queryParams(map) taken away from WebTarget?


I'm doing a migration from Jersey's Client API (https://jersey.java.net/documentation/latest/client.html) 1.x to 2.x, and the queryParams(map) method of WebResource did not make it over to WebTarget, or it's Builder, or it's Invocation. There's just queryParam ( key, value).

Is there another way to add multiple parameters? I'm not adding a list, like: Handling Multiple Query Parameters in Jersey


Solution

  • Call API in below way -

    target = target.queryParam("foo", "fooValue").queryParam("bar", "barValue");
    

    By this way, you can add any number of query params. If you have map, then just iterate map and write this line in loop.

    I think reason behind removing map and using this approach is query param can contain multiple query parameters with same name and different value. However, the same can not be achieved using map.