users@jersey.java.net

Re: [Jersey] Does Jersey understand generics marshalling/unmarshalling ??

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Fri, 13 Aug 2010 10:29:33 -0700

On Fri, Aug 13, 2010 at 4:18 AM, Paul Sandoz <Paul.Sandoz_at_oracle.com> wrote:
> Hi Isaac,
>
> The default support for JSON uses integration with JAXB and JAXB does
> support this general type of wrapping concept out of the box. It needs to
> know statically the stuff it needs to marshall/unmarshall.
>
> It is possible to define your own message body readers/writers that supports
> such wrapping and can defer to other message body readers/writers for the
> wrapped type. Such readers/writers have access to the parameterized Type.
>
> And, it is also possible to use Jackson with Jersey. So i suspect if you can
> use Jackson to support your requirements you can plug it into Jersey.

Jackson also will fully support generics type information, within
limitations of JVM type erasure.
So signatures (of fields, methods) that contain generic type
information will be used as expected.
Only tricky case is type when serializing root object; if it is
generic, TypeReference needs to be used (or explicitly constructed
JavaType).
So in this respect it is like JAXB, with exception that there is no
need to pre-register classes involved.

-+ Tatu +-