On Tue, Jul 23, 2019 at 5:19 PM Saurabh Pawar <[email protected]> wrote: > > 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? >
If and when there is `defaultImpl` specified, missing type id should result in instance of default type being constructed, so this should work. So if you can create a standalone test to reproduce the problem, please file a Github issue. -+ Tatu +- -- 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/CAL4a10iGCt-e3avtsaOCQLFJTHUprGdH7w-YUXTgC7fVL9-akg%40mail.gmail.com.
