users@jersey.java.net

Re: [Jersey] Better solution than expandLevel parameter

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 25 Sep 2009 10:21:03 +0200

Hi Ido,

This appears to be how to deal with hypermedia relationships between
resources such that a parent resource can include the representations
of the child resources (if required) so that the client does not have
to make 2 or more requests. Does that capture the general gist of
things?

For such cases there needs to be something in the URL defining what
the parent resource should include. I have seen solutions (not using
JAX-RS) that define a simple query language (the Microsoft approach
comes to mind, or the talk at JavaOne 2009 by IIRC LinkedIn engineers).

Note that IMHO i considered that rather than embedding complex query
statements into the URL one could POST an entity with the URL to a
resource and the query and receive back a URI one can perform a GET on
to retrieve the results.

I think form a tooling perspective for CRUD'fying DBs one could
develop a richer approach that what current NBs supports.

It would help of you could provide a simple example of what you would
like to see to help ascertain whether you want a general querying
mechanism or something more focused and application specific.

Paul.

On Sep 24, 2009, at 2:16 PM, Ido Ran wrote:

> Hi,
> All the RESTful services example of jersey (which get created by the
> wizards) use a url parameter name
> expandLevel to control how much of the object graph should be
> serialized from the server to the client.
>
> This is a technical solution which does not feet to me. For example,
> I have entity of type Person, I also
> have an entity of type Relation and another entity of type
> RelationType.
> As you can see Person entity have a collection of Relation(s)
> entities and Relation entity have a
> RelationType.
>
> When I ask for myserver.com/relations I expect to get all the
> relations back. If I want to get in one go
> all the relations and their type I ask for the url myserver.com/
> relations?expandLevel=2 but now I get all
> the relations, all their type but also all the representation of the
> Persons.
>
> Also since I have a circular reference here, Person have relations
> and Relation has two Person (from and
> to) if I ask for the url myserver.com/relations?expandLevel=500 I'll
> get unending xml file which just
> recursively say the same thing over and over.
>
> Is there a better solution to this problem? way to indicate which
> entities I want to get back and how
> much of them?
>
> Thank you,
> Ido.
> ------- Additional comments from sandoz Thu Sep 24 08:43:51 +0000
> 2009 -------
> Note that this is not a Jersey issue but a NetBeans tooling issue.
>
> I think the NetBeans tooling provides a simple solution but in
> general this is a
> modeling issue, and i think it depends on what you are attempting to
> model, and
> for cases for restricting what information is returned in a
> representation it
> may require a richer way of defining the restrictions. Also one can
> go a bit
> other the top here and start providing SQL-like queries into URIs.
>
> The recursive aspect is definitely a subtle bug that could be logged
> against the
> netbeans tooling.
> ------- Additional comments from ido_ran Thu Sep 24 09:40:32 +0000
> 2009 -------
> Hi,
> Thank you for the answer.
> I understand that the wizard are NetBeans issue, but I was talking
> about what is the best practice of using
> Jersey this way.
> I also agree that the model of the solution (data) may change the
> way we ask for the data.
>
> The issue here is how to deal with relation (not by Relation entity)
> between entities.
>
>