3

In jersey version 1.4 (at least that's the only reference I can find online) there was com.sun.jersey.api.client.WebResource where you could send a list of parameters using Webresource.queryParams() ... seems that method no longer exists in jersey-client 2.x ... I imagine it's still possible to do this (without having to manually put together a query string)? There is class WebTarget with a method:

public WebTarget queryParam(String name, Object... values);

but no queryParams() method.

Esko
  • 129
  • 1
  • 3
  • 12

2 Answers2

6

Just call queryParam() multiple times. Such as

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

or in case you have a map you can loop through the entries:

for (Map.Entry<String, Object> entry : map.entrySet()) {
    target = target.queryParam(entry.getKey(), entry.getValue());
}
Sebastian
  • 5,721
  • 3
  • 43
  • 69
3

You can use the public WebTarget queryParam(String name, Object... values); method:

target.queryParam("foo", "fooValue", "barValue", "anythingElseValue");

If you do have a List already, just pass that as a plain array:

List<String> list = new ArrayList<>();
list.add("foo");
list.add("bar");

target.queryParam("foo", list.toArray());
Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78