users@jersey.java.net

Re: Generating urls and controlling rendering/serialization

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Thu, 28 Feb 2008 10:43:25 -0500

On Feb 28, 2008, at 7:23 AM, Jo Størset wrote:
>
> For now I have done a hack by adding a url bean property to my
> domain objects (the ones that represent rest resources), and on my
> @GET methods I explicitly write this property before returning the
> object (for jaxb serializing). Is there any way to avoid this?
>
Note that you can inject UriInfo into a MessageBodyWriter as well as a
resource class so you have access to all the same URI information when
serializing.

> The first problem I have is the fact that every resource needs to
> explicitly know how to generate urls to every other resource(type)
> that is to be linked in the representation. This leads to *a lot* of
> duplication, and I don't like a so central part of a rest based
> application to lead to such an amount of manual and error prone
> duplication.
>
> Maybe I haven't understood the model good enough, but the second
> problem I have is that the jsr-311 model seems to dictate a
> duplication of the domain model in a seperate resource layer on top.
> All my resource objects need to know the mapping between the domain
> objects and the correponding resource objects containing the
> annotation mapping (and usually som hard coded path attibutes as
> well) for every link it is to generate.
>
See the UriBuilder.fromResource and UriBuilder.path(Class) methods.
These allow you to generate URIs without duplicating the value of
@Path annotations. Is that the kind of thing you are looking for ?

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.