2

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

Community
  • 1
  • 1
mojo-jojo
  • 145
  • 1
  • 1
  • 7

1 Answers1

2

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.

Vikas Sachdeva
  • 5,633
  • 2
  • 17
  • 26
  • This is what I had to do, but I was confused why, when the API still has methods like headers(map), but not one for queryParams... – mojo-jojo Nov 22 '16 at 23:16
  • @mojo-jojo I just edited my answer. Hope it is clear now. For headers, we can still use map because an HTTP request can not contain duplicate headers – Vikas Sachdeva Nov 23 '16 at 00:20
  • Ok, that explains why I've seen an implementation using MultiValuedMap ... thanks. – mojo-jojo Nov 23 '16 at 18:21