users@jersey.java.net

[Jersey] Re: Json output for subclasses

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Thu, 30 Dec 2010 12:00:04 -0800

On Thu, Dec 30, 2010 at 7:38 AM, Adam Walczak <me_at_adamwalczak.info> wrote:
> The difference between the two is that the default ObjectMapper
> ignores JAXB anntotations and does things in his own way and Jerseys
> ObjectMapper uses an annotation introspector.

Minor clarification: latter would be one of Jersey's json handlers, as
ObjectMapper is Jackson abstraction.

It is true that if one just instantiates ObjectMapper, it does not
come with JAXB annotation handler. But when instantiated via Jersey,
it should be configured: and it is possible to manually insert it too,
see [http://wiki.fasterxml.com/JacksonJAXBAnnotations]

Now: with Jackson, use of @XmlRootElement is never needed, so it can
be freely omitted.
Similarly, default introspection settings are such that all public
getters (and any setters, including protected and private ones) are
found.
Use of JAXB annotations is often unnecessary; exception being cases
where one wants to use private fields.

So in general use of Jackson data binding (via Jersey's POJO mapper,
or directly) should be simpler than using other jersey mappers.

-+ Tatu +-