I have polymorphic types and serialization when the type parameter is 
passed in JSON works fine. 


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;import 
com.fasterxml.jackson.annotation.JsonSubTypes;import 
com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonIgnoreProperties(ignoreUnknown = true)@JsonTypeInfo(use = 
JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = 
"type", defaultImpl = Dog.class)@JsonSubTypes({
    @JsonSubTypes.Type(value=Dog.class, name="dog"),
    @JsonSubTypes.Type(value=Cat.class, name="cat")})    public class Animal { 
... }
public class Dog extends Animal { ... }public class Cat extends Animal { ... }

{"name":"Tom", type="cat"} // this works as expected

@POST@Produces(MediaType.APPLICATION_JSON)public Response animal(Animal animal) 
{...}

But, if I directly want to get a subtype object without passing type it 
does not work. 

@POST@Produces(MediaType.APPLICATION_JSON)public Response dog(Dog dog) {...}

{"name":"Tom"} // this wont work

 

Missing type id when trying to resolve subtype of [simple type, class 
....Dog]: missing type id property 'type' 

Any way to achieve this?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/c3a16eb2-cf0b-46ea-af4e-e95400fe365a%40googlegroups.com.

Reply via email to