Skip to content
Advertisement

Jackson deserialization to concrete polymorphic class

I have following Jackson annotated classes (Kotlin)

JavaScript

I try to deserialize JSON that does not contain type property but I provide concrete class so it should not matter

JavaScript

I get Missing type id when trying to resolve subtype of ... anyway. Is there a way how to tell Jackson to use the type provided in the deserialization and not to try find it from the type property?

Advertisement

Answer

There’s a default implementation class to use for deserialization via defaultImpl:

JavaScript

From the Javadoc:

Optional property that can be used to specify default implementation class to use for deserialization if type identifier is either not present, or can not be mapped to a registered type (which can occur for ids, but not when specifying explicit class to use). Property has no effect on choice of type id used for serialization; it is only used in deciding what to do for otherwise unmappable cases.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement