users@jersey.java.net

Re: Collection serialization in RESTful service

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 23 Oct 2007 16:16:31 +0200

Florian Rosenberg wrote:
>> Some possible solutions:
>>
>> 1) We could provide a Collection type entity provider that checks if all
>> of the objects are JAXB element objects, if so a root element is
>> written out and then each JAXB element is marshalled.
>>
>> 2) A generic collection type class with an entity provider:
>>
>> class CollectionType<T> {
>> Collection<T> c;
>>
>> CollectionType(Collection<T> c) { ... }
>> }
>>
>> The entity provider can then create a JAXBElement instance:
>>
>> QName q = // work out root element name from c
>> new JAXBElement(q, CollectionType.class, c)
>
> I would go with (1) just for simplicity and it allows the user to stick to
> his preferred API without used the typed collection.

Right. Since similar classes for 2) i have mentioned will be required
for an implementation of 1) i think i can expose various things out
depending on if developers need simplicity, performance or configuration
of the root element and for each case don't require to create a
collection class for each entry class.

https://jersey.dev.java.net/issues/show_bug.cgi?id=18


> when going for (1)
> you need to find a name for the root element, eg., customers if the
> objects in the collection are of type Customer.
>

Yes, same applies for 2). I need some pluralizer code that given a
singular word returns the plural. I suppose i could append an 's', know
of anything better i could use?

Paul.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109