Hi everyone,


I've been using Jackson for a while now, and there's one thing that has 
been bothering me. Maybe I'm doing it the wrong way. Let's assume we have 
the following classes:


@JsonSerialize(as = AbstractAnimal.class)  // these two 
lines...@JsonDeserialize(as = AbstractAnimal.class) // ...are not doing what I 
wantpublic interface Animal { /* ... */ }
@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = 
"type")@JsonSubTypes({
    @Type(value = Dog.class, name = "dog"),
    @Type(value = Cat.class, name = "cat")})public abstract class 
AbstractAnimal implements Animal { /* ... */ }
public class Dog extends AbstractAnimal { /* ... */ }public class Cat extends 
AbstractAnimal { /* ... */ }


So there's an interface, accompanied by an abstract base class. The 
abstract base class lists the JsonSubTypes.

   - If I try to deserialize a JSON string and ask for AbstractAnimal.class, 
   then it works.
   - However, deserializing a JSON string with type Animal.class does *not*
    work.

The reason why deserializing as Animal.class does not work is that 
@JsonSerialize(as 
= AbstractAnimal.class) attempts to really deserialize Animal as the *abstract 
base class*, which of course fails. What I would actually like to do here 
is to redirect Jackson's type inference mechanism to *recursively* check 
the annotations on AbstractAnimal, rather than using AbstractAnimaldirectly.


How is this done correctly in Jackson?


Thanks,


Martin

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to