users@jersey.java.net

Re: Collection serialization in RESTful service

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 29 Oct 2007 10:07:00 +0100

Florian Rosenberg wrote:
> hi paul,
>
> On Fri, October 26, 2007 07:19, Paul Sandoz wrote:
>> Hi Florian,
>>
>> Your attachment looks really good.
>>
>> It should also be possible to implement the readFrom method as a SAX
>> filter that push fake start/end document events wrapped around each
>> child of the root element and pass this to JAXB unmarshalling.
>
> I guess it should work, I didn't do it in the first place because I had no
> need for it, and it was just a quick try. I try to add it at some point
> early next week and upload a new version if it works.
>

OK.


>> Also not that the current JAXB entity provider supports JSON as well as
>> XML, it should be easy to support marshaling, but unmarshaling may be
>> tricker (depending on the low-level JSON parsing support).
>
> I'm not sure what you mean. I don't really need JSON support in my
> project, so I've not looked into that. So you mean we can serialize the
> whole collection as JSON and by writing a custom entity similar to the one
> I've uploaded?
>

Yes, the JAXB entity provider currently shipped supports XML and JSON so
it would be good to be consistent with that. I don't think it is
necessary to do that right now but something we can work on later.

(In general i need to refactor the entity provider internals in the
runtime to work from the Java type and mime type, that way we can
separate out the XML and JSON JAXB implementations).


>> My only main concern Collection<?> is very general and this is specific
>> to JAXB, and Collection<?> may make sense in other contexts for other
>> Java types.
>
> Agree, that's not the cleanest way, but I could not think of any other
> ways except using Collection<?>. I have some check in the "writeTo" to see
> if all elements of the collection have the JAXB @XmlRootElement
> annotation.
>
>> Perhaps we can include this but not add it by default to the
>> javax.ws.rs.ext.EntityProvider file? Thus developers wishing to avail of
>> this functionality need to explicitly create the services file.
>
> +1. I'll add the service file to the next version.
>

Great.

Paul.

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