2009/3/25 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>
> On Mar 25, 2009, at 4:22 PM, James Strachan wrote:
>
>> 2009/3/25 Imran M Yousuf <imyousuf_at_smartitengineering.com>:
>>>
>>> Hi,
>>>
>>> I have a generic REST question and am wondering how to achieve it in
>>> using JAX-RS and Jersey.
>>>
>>> I would take an example to illustrate the scenario. There is a obejct
>>> 'A' which is a resource and there is 'B' which is also a resource Now
>>> 'A' has one or more 'B'. Now when resource 'A' is accessed it will
>>> 'have' 'B' as well, in terms of REST we would want them to referred to
>>> using their respective URIs. Now my question is if I am using
>>> JAXB/JSON for exporting my resources how can I achieve this?
>>
>> FWIW I've hit similar issues; needing to refer to related resources
>> from other resources. I've tended to add URI attributes to the JAXB
>> beans so at least there's some way to return the links in the XML/JSON
>> representation.
>>
>> Its not very DRY as the URI path is then encoded once in @Path and
>> then in one or more JAXB beans via their URI attribute - for each bean
>> type which refers to a B. There's been a few threads about this in the
>> past on this list. Ideally one day we'd be able to just store (say)
>> the ID of the related resource and from the related @Path annotation
>> some utility could automatically generate the URI for a resource bean.
>>
>>
>> e.g. it'd be nice to do something like this one day...
>>
>> public class A {
>> private String idForB;
>>
>> public String getUriForB() {
>> return UriBuilder.for(B.class).withId(idForB);
>
> You can do this:
>
> UriBuilder.fromResource(B.class).build(idForB);
Awesome! :) I'd not spotted that!
That only works with resource beans right? I wonder if it'd work if we
used @Path on a DTO rather than a Resource?
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://fusesource.com/