How do you map multiple query parameters to the fields of a bean on Jersey GET request?

In Jersey 2.0, you’ll want to use BeanParam to seamlessly provide what you’re looking for in the normal Jersey style.

From the above linked doc page, you can use BeanParam to do something like:

public FindResponse find(@BeanParam ParameterBean paramBean) 
    String prop1 = paramBean.prop1;
    String prop2 = paramBean.prop2;
    String prop3 = paramBean.prop3;
    String prop4 = paramBean.prop4;

And then would contain:

public class ParameterBean {
     public String prop1;

     public String prop2;

     public String prop3;

     public String prop4;

I prefer public properties on my parameter beans, but you can use getters/setters and private fields if you like, too.

Leave a Comment