users@jersey.java.net

Re: [Jersey] How to pass associative data to a resource?

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 17 Feb 2010 17:03:14 -0500

On Feb 17, 2010, at 4:50 PM, Dário Abdulrehman wrote:
>
> On Wed, Feb 17, 2010 at 9:36 PM, Marc Hadley <Marc.Hadley_at_sun.com> wrote:
> On Feb 17, 2010, at 3:25 PM, Dário Abdulrehman wrote:
>
> > I would like to provide a resource that expects an associative array, for example { abc -> 1 , def -> 2} as its input:
> >
> > resource?gene=abc&id=1&gene=def&id=2...etc
> >
> > The above example obviously won't work since the parameters are not interpreted by the resource in the specified order.
> >
> resource?abc=1&def=2 perhaps ?
>
> But abc, def are the values I want to pass and not the parameter names.
> Then how do I declare the QueryParams?
>
> public Response doGet(@QueryParam("?") String, ...)
>
Rather than using @QueryParam you can get a map of all the supplied query parameters from

https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/core/UriInfo.html#getQueryParameters()

e.g. public Response doGet(@Context UriInfo uriInfo) {...}

Then you can iterate over the keys to get abc, def etc.

Marc.

>
>
>
> If you need additional qualifiers you could use matrix parameters and path segments like:
>
> resource/genes;abc=1&def=2/...
>
> Marc.
>
> > How can I achieve this without resorting to hand-crafted solutions, like providing each pair as a single value, separated by a designated token, ex: gene_id="abc_at_1"&gene_id="def_at_2"...etc ?
> >
> > Thanks.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>