dev@jsr311.java.net

Re: Representation<T> and Entity<T>

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 10 Apr 2007 10:42:28 -0400

On Apr 10, 2007, at 8:47 AM, Jerome Louvel wrote:

>
>> If there is a header that is decided dynamically (based on
>> some computation) you cant specify it with static metadata. I
>> would much prefer the Representation<T> wrapper to forcing
>> adding the metadata to the returned entity.
>
> Yes you can. If you annotate your getModificationDate() method with
> the
> @LastModifiedDate annotation, then your method can return a data that
> changes dynamically. Same for other metadata.
>
>> I certainly would
>> like to have the flexibility to use arbitrary domain objects
>> (that may be written by other developers) as my content
>> payload and register serializers for them. This is not
>> uncommon in large projects.
>
> This is a useful case. I need to think more about how (de-)
> serialization of
> representation POJOs should be supported. But, if you control your
> resource
> POJO, then you can add annotated "serialization" method like:
>
> @Resource
> public MyResource {
>
> Foo foo; // the representation domain object to reuse
>
> @Representation("application/foo-xml")
> public Document toXML() {
> // logic to generate a DOM document
> // from the current "foo" instance.
> }
>
> @Representation("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 ?

Marc.

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