On Tue, Aug 25, 2009 at 1:53 PM, DirkM<dirk_at_olx.com> wrote:
>
>
...
> I was having a similar problem, and decided to use
> http://code.google.com/p/google-gson/ GSON to handle writing JSON for
> Jersey. It outputs nulls more intuitively than JAXB, which is constrained by
> having originally been designed for XML.
...
> In order to make Jersey write JSON using a custom writer, you need to create
> a Provider that implements MessageBodyWriter. I've included my version
> below. Note that I'm using Guice, so there are some extra annotations and
> Gson gets injected (so you won't see the configuration changes I suggested
> above)
...
As a sidenote, same is true for Jackson
(
http://wiki.fasterxml.com/JacksonHome), except that JAX-RS provider
implementation is already included in Jackson distribution (in
"jackson-jaxrs" jar).
I agree in that this (using object-to/from-JSON, with no intermediate
JAXB mapping) often makes sense, possibly alongside xml output using
JAXB.
-+ Tatu +-