users@jersey.java.net

[Jersey] Re: 2.x, how to populate the parameter bean on Jersey GET request ?

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Wed, 4 Mar 2015 14:00:24 +0100

I’m afraid there is no way for you to inject query parameters without annotating the field(s) with @QueryParam in JAX-RS. And I do not see us adding anything like that in the future. JAX-RS is a much more generic REST framework that cannot be compared with limited use cases supported by Struts. We cannot introduce certain conventions or “simplifications” without jeopardizing other important use cases that we need to support.

IOW, if you want to inject query parameters in JAX-RS, use @QueryParam. Nuff said. :)

Marek

> On 04 Mar 2015, at 08:53, joey.lv <joey.lv_at_7road.com> wrote:
>
> A service class has a @GET operation that accepts multiple parameters. These parameters are passed in as query parameters to the @GET service call.
>
> @GET
> @Path("find")
> @Produces(MediaType.APPLICATION_XML)
> public FindResponse find(@QueryParam("prop1") String prop1,
> @QueryParam("prop2") String prop2,
> @QueryParam("prop3") String prop3,
> @QueryParam("prop4") String prop4, ...)
> The list of these parameters are growing, so I would like to place them into a single bean that contains all these parameters.
>
> @GET
> @Path("find")
> @Produces(MediaType.APPLICATION_XML)
> public FindResponse find(ParameterBean paramBean)
> {
> String prop1 = paramBean.getProp1();
> String prop2 = paramBean.getProp2();
> String prop3 = paramBean.getProp3();
> String prop4 = paramBean.getProp4();
> }
> Somebody said that to use @BeanParam, but it need add @QueryParam for every property in my bean.
>
> So, is there any way I can avoid placing @QueryParam for every property in my bean?
>
> In Struts2 application, if there's a quest URL like this:
> http://../queryUser.do?user.name=x&user.address=y <http://../queryUser.do?user.name=x&user.address=y>
> Struts 2 can auto populate parameter bean in Action, the User bean just has setter()/getter().
> public String queryUser(User user){
> ..
> ..
> ..
> }