users@jersey.java.net

Better solution than expandLevel parameter

From: Ido Ran <ido.ran_at_gmail.com>
Date: Thu, 24 Sep 2009 15:16:04 +0300

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 <sandoz_at_dev.java.net> 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 <ido_ran_at_dev.java.net> 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.