users@jersey.java.net

[Jersey] Re: Json output for subclasses

From: Franz Wong <franzwong_at_gmail.com>
Date: Fri, 31 Dec 2010 20:13:43 +0800

Thanks your all!

Finally I have decided to return a String which is generated by Jackson's
ObjectMapper. It seems work for me. :)

Franz

On Fri, Dec 31, 2010 at 4:00 AM, Tatu Saloranta <tsaloranta_at_gmail.com>wrote:

> 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 +-
>