users@jersey.java.net

RE: delimiter for QueryParam using List<T>

From: Turner, George <george.turner_at_lmco.com>
Date: Wed, 17 Jun 2009 07:21:31 -0600

Thanks Paul.

This is a REALLY surprising answer, because I would think it is a
non-standard usages of query parameters. Most implementations would
throw all of the parameters into a Map and then you would only be able
to retrieve the last one entered. I was expecting a pipe "|" or
something but not this answer. Is there a W3C reference to this style?
I had a class like the one given that split on a comma, but dropped it
to use the List<T> construct, but couldn't get it to work, but now I
know why.

Thanks

Gene

-----Original Message-----
From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Sent: Wednesday, June 17, 2009 03:24
To: Turner, George
Subject: Re: delimiter for QueryParam using List<T>

Hi Gene

Given, for example, the following URL:

   http://host:8080/path?a=1&a=2

That results in the following resource method to be invoked:

    @GET
    public String get(@QueryParam("a") List<String> la) {
    }

Then the list "la" will contain the values "1" and "2".

i.e. the list handles *multiple* values of the same parameter. If you
want to support some form of lexical syntax for a particular value then
you will have to write your own class that conforms to the rules of
classes e.g. a constructor that takes a String value, like that which is
used in the Sparklines sample (see code below).

Paul.

P.S. i strongly recommend you use the jersey users list, that way you
may get a quicker response and others can also benefit from the
responses as well.

public class IntegerList extends ArrayList<Integer> {
     public IntegerList(String s) {
         super();

         for (String v : s.split(",")) {
             try {
                 add(Integer.parseInt(v.trim()));
             } catch (Exception ex) {
                 ex.printStackTrace();
                 throw new WebApplicationException(400);
             }
         }
         if (isEmpty())
             throw new WebApplicationException(400);
     }
}

On Jun 16, 2009, at 7:13 PM, Turner, George wrote:

> Paul,
>
> I have searched everywhere and cannot find documentation for the valid

> delimiter when using the List<T> QueryParam. I have always used a
> comma when handling it manually before Jersey, but would like to now
> use the the RI to handle this, but can't seem to get anything to work,

> even with the 1.1.0-ea.
> Help?
>
> Thanks
>
> Gene
>
> George (Gene) Turner
> <image001.png>
> Senior Staff Software Engineer
> Information Systems & Global Services
> Work:(719) 277-5244 Cell:(719) 237-0490 george.turner_at_lmco.com
>
>