users@jersey.java.net

Re: [Jersey] Error when unmarshalling abstract property via JSON

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Fri, 10 Sep 2010 09:51:39 -0700

On Fri, Sep 10, 2010 at 2:20 AM, Paul Sandoz <Paul.Sandoz_at_oracle.com> wrote:
> Hi Peter,
>
> I did not realize you were using JSON, so was the original error you
> mentioned the result of sterilizing as JSON? i presume so because in your
> JAXBContext you are only passing the Diagram class which is essentially what
> Jersey does.
>
> So this is an issue with the JAXB/JSON serialization.
>
> What version of Jersey are you using?
>
> Have you tried with the natural convention?
>
> The alternative is to switch to using Jackson. Tatu, will Jackson work in
> this scenario?

In general yes, Jackson can support handling of polymorphic types,
starting with Jackson 1.5 ("jackson five").
There are couple of alternative ways to achieve this, depending on
whether it is just difference between public interface/abstract class
and non-public implementation, or truly polymorphic type.
I assume it would be latter. If so, one typically uses @JsonTypeInfo
annotation on base class, and from thereon things work.
No registration of types is needed if using class-name as type
identifier; if type names are used, there are couple of ways to
indicate name/subtype mappings.

-+ Tatu +-