On Mar 25, 2008, at 9:20 AM, Leif Gensert wrote:
> hello everyone,
>
> I wonder if it is possible to get multiple query or template parameter
> already as a collection data type. I would like to see something like
> that
>
> http://localhost:8080/user/1,2,3,4
>
Those aren't query parameters. Query parameters would look something
like:
http://localhost:8080/user/?id=1&id=2&id=3&id=4
You could then use
@QueryParam("id") List<String> ids
to extract the list of values for the "id" query parameter. BTW,
currently this use of List is not part of the JSR API, its a Jersey
extension, the 0.8 API will include support for List, Set and SortedSet.
> the resource class for this would then look something like this:
>
> @Path("user/{userid}")
> public class UserResource
> {
> @ProduceMime("application/xml")
> @GET
> public ReturnValue<Consultant>
> getConsultantInfos(@PathParam(userids) List<String> user)
> {
> ...
>
> I'd like to have a list named user which contains multiple values
> ("1", "2", "3" and "4").
>
> However that is what I tried. And that is what happened:
>
> The variable user is an arraylist which contains only one element
> (which is "1,2,3,4").
>
> I alsor tried with delimiter ";" and then the arraylist only contains
> 1 element ("1").
>
> I managed to get a workaround by defining an own collection which has
> a constructor with one string. This string will then be tokenized to
> muluiple values.
>
That's the right way to do this, perhaps we should provide a generic
class for this with Jersey to save everyone writing their own.
Marc.
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.