dev@jsr311.java.net

Re: Representation<T> and Entity<T>

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 10 Apr 2007 11:40:47 -0400

On Apr 10, 2007, at 10:49 AM, Jerome Louvel wrote:
>
> @Resource
> public MyResource {
> Foo foo; // the associated domain object
>
> @Output("application/foo-xml")
> public Document toXML() {
> // logic to generate a DOM document
> // from the current "foo" instance.
> }
>
> @Output("application/foo-json")
> public JSONObject toJSON() {
> // logic to generate a JSON object
> // from the current "foo" instance.
> }
> }
>
>> Is the above meant to be a resource class or a representation
>> ? I.e.
>> are the toXML and toJSON methods meant to respond directly to a HTTP
>> GET or is there another class that does that and returns an instance
>> of the above ?
>
> It is meant to be the resource POJO. It is one way to design this,
> which is
> interesting when the wrapped domain object ("foo" member here) isn't
> annotable.
>
> I have changed the @Representation annotations to the more explicit
> @Output
> ones. The JSR implementation should compare the representation
> variants
> available and select the best one based on the client preferences
> (content
> negotiation).
>
Presumably the presence of @Output indicates the method should be
exposed as a HTTP method and the method is defaulting to GET based on
the omission of any @Method annotation ?

Presumably there would either be application specified serializers
for Document and JSONObject or it would use default ones defined by
the API.

Marc.

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