ArcBees / GWTP

A complete model-view-presenter framework to simplify your next GWT project.
Other
334 stars 132 forks source link

Serialize bean-like objects to url paramaters automatically #501

Open spg opened 10 years ago

spg commented 10 years ago

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:

Pacane commented 10 years ago

That's a good idea.

christiangoudreau commented 10 years ago

https://jersey.java.net/documentation/latest/jaxrs-resources.html#d0e1889

confile commented 10 years ago

+1 good idea, I would recommend that as well

reinert commented 10 years ago

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.

christiangoudreau commented 10 years ago

That's achievable through @BeanParam which is part of Jax-RS 2.0 spec. Let's plan this for 1.4

hacker-cb commented 7 years ago

So, is there any way to use @BeanParam now?