Handling Multiple Query Parameters in Jersey

If you change the type of your item method parameter from String to a collection such as List<String>, you should get a collection that holds all the values you are looking for.

@GET
@Path("/foo")
@Produces("text/plain")
public String methodImCalling(@DefaultValue("All") 
                              @QueryParam(value = "item") 
                              final List<String> item) {
   return "values are " + item;
}

The JAX-RS specification (section 3.2) says the following regarding the @QueryParam annotation:

The following types are supported:

  1. Primitive Types
  2. Types that have a constructor that accepts a single String argument.
  3. Types that have a static method named valueOf with a single String argument.
  4. List<T>, Set<T>, or SortedSet<T> where T satisfies 2 or 3 above.

Leave a Comment