Serialize bean-like objects to url paramaters automatically
Suppose I flush a bean from an GWT Editor, and that bean represents search parameters:
class SearchParams {
String name;
int age;
State state;
String zip;
}
A common REST practice is to use a GET request and pass the search as query params:
[GET] /search?name=Bob&age=20&state=OH&zip=90210
Right now, the only way to build this query string is this is to decompose the POJO into the service method:
@Path("search")
public interface UsersService {
@GET
RestAction<List<User>> searchUsers(@QueryParam("name") String name, @QueryParam("age") int age, @QueryParam("state") State state, @QueryParam("zip") String zip);
It would be awesome to pass the SearchParams object as-is to the service method:
@Path("search")
public interface UsersService {
@GET
RestAction<List<User>> searchUsers(@QueryParam("") SearchParams searchParams);
This imposes a few questions that need answers:
- How do we translate nested objects (e.g. : SearchParams -> Address -> ...) into query params?
- What annotation should be used in the service method? Is there an already existing JAX-RS annotation that exists for this?
That's a good idea.
https://jersey.java.net/documentation/latest/jaxrs-resources.html#d0e1889
+1 good idea, I would recommend that as well
When filtering resources, it's a good practice to place matrix params after them, like /groups;class=a.
It's not the case presented (a search - action - endpoint) but if you're going to developer such feature, you should provide options of uri forming.
That's achievable through @BeanParam which is part of Jax-RS 2.0 spec. Let's plan this for 1.4
So, is there any way to use @BeanParam now?