1

I need to know whether I can deserialize a generic object to it's defining type without having an additional property or without mentioning the type in an annotation.

Ex:-

@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")

In above I have to mention the @class property, and another way is

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
@JsonSubTypes({
 @JsonSubTypes.Type(value = Dog.class, name = "Dog"),
 @JsonSubTypes.Type(value = Cat.class, name = "Cat")
})

in the above example, we are defining the subclasses and a custom type.

Using a custome deserializer StdDeserializer<T>

Is there any other way to do this please tell me.

MaxExplode
  • 1,977
  • 2
  • 17
  • 27

1 Answers1

2

If you can figure out a way to determine the object subtype from the JSON data, you could write a custom TypeId resolver to handle it for you. See Jackson Custom TypeId Resolver.

Baldy
  • 2,002
  • 14
  • 14