Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jersey 1.x to 2.x translation issue - queryparams  RSS feed

 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Jersey 1.x there was a WebResource.queryParams() method that accepted a MultivaluedMap. Our code made us of this to centralize REST client calls.

Now we are finally upgrading to Jersey 2.x and the WebTarget class has a queryParam() method, but not a queryParams() method. I could write a for loop (actually, two nested for loops since each entry in the MultiValuedMap could have multiple values), but before I did that I was wondering if there was a better way.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Johnson wrote:
Now we are finally upgrading to Jersey 2.x and the WebTarget class has a queryParam() method, but not a queryParams() method. I could write a for loop (actually, two nested for loops since each entry in the MultiValuedMap could have multiple values), but before I did that I was wondering if there was a better way.


The signature of the queryParam() method on WebTarget allows multiple values to be passed for the same param and even the javadoc makes a note of it:

Create a new WebTarget instance by configuring a query parameter on the URI of the current target instance. If multiple values are supplied the parameter will be added once per value. In case a single null value is entered, all parameters with that name are removed (if present) from the collection of query parameters inherited from the current target.


So it looks like the JAX-RS client API introduced this standard API to pass multiple values for a param.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, now that I'm reading the quoted bold text from the javadoc in my post, I think I was wrong about that API. I'll have to do a quick test to be sure.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!