users@jersey.java.net

Re: [Jersey] Serializing empty arrays as a result

From: Tom Schindl <tom.schindl_at_bestsolution.at>
Date: Wed, 11 Nov 2009 10:26:15 +0100

Hi Jakub and Tatu,

Jakub Podlesak schrieb:
> On Tue, Nov 10, 2009 at 05:13:18PM -0800, Tatu Saloranta wrote:
>> On Tue, Nov 10, 2009 at 11:11 AM, Tom Schindl
>> <tom.schindl_at_bestsolution.at> wrote:
>>> Hi,
>>>
>>> I'm running into a problem with the Jersey-JSON serialization because I
>>> need to satisfy an API which require me to serialize empty Collections.
>>>
>>> The external party requires me to send JSON in the following format:
>>>
>>> --------8<--------
>>> {
>>> a : "Blabla",
>>> l : []
>>> }
>>> --------8<--------
>>>
>>> but it looks like this is not possible to achieve with jersey because if
>>> the l-attribute holds an empty list or null it is not part of the
>>> serialized response:
>> I let others explain if and how this is possible with JAXB and bundled
>> json handlers, but I will add the usual comment that
>
> Unless you wanted to use the low-level JSON approach and JSONArray/JSONObject
> classes, you would indeed need to leverage the JacksonJsonProvider as suggested by Tatu.

Thanks. Just included the JacksonJsonProvider into my application and it
looks good so far. Would it be possible at all to bring in such a
support to jersey itself?

If yes I'd try provide you a patch for it but before I start searching
through the code I'd like to know if this is even possible at or a
limitation of underlying infrastructure.

Tom

-- 
B e s t S o l u t i o n . a t                        EDV Systemhaus GmbH
------------------------------------------------------------------------
tom schindl                                        geschaeftsfuehrer/CEO
------------------------------------------------------------------------
eduard-bodem-gasse 5/1    A-6020 innsbruck      phone    ++43 512 935834