users@jersey.java.net

Re: [Jersey] Serializing empty arrays as a result

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Tue, 10 Nov 2009 17:13:18 -0800

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
JacksonJsonProvider does include empty lists and nulls by default (can
be changed so that nulls are excluded).
JacksonFAQ [http://wiki.fasterxml.com/JacksonFAQ] (6.2.1) outlines how
this provider can be used -- it can use JAXB annotations, as well as
Jackson's own, but most of the time basic property auto-detection
works fine.

-+ Tatu +-