Exception while deserializing json payload of abstract kotlin class from disk using BasicPolymorphicTypeValidator activateDefaultTyping #810
-
Hi All, I have serialized a kotlin data class (Movie) which inherits a abstract class (Programme). If I serialize it as a programme Jsonmapper has difficulty and gives below exception com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `Programme` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information When I introduced Polymorphic Deserializations using BasicPolymorphicTypeValidator activateDefaultTyping(). I am getting below exception. Basically library is not able to write the type details of root element. Apart from using a wrapper class to hold my payload, any other idea please. com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve subtype of [simple type, class Programme]: missing type id property '@class' Serialized payload onto disk {"lastInSeason":true,"synopsis":["java.util.ArrayList",["my synopsis1"]]} Library version: code is here https://github.com/srusanvin/kotlinabstractclassserializer |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Are you sure you want to use "Default Typing", instead of adding This also looks like it might not be Kotlin specific. |
Beta Was this translation helpful? Give feedback.
-
Could you just add But as to:
No. Due to Java (JVM) type erasure, declared type of reference is not visible during runtime; so while you may have reference of type This is the specific difference between given Root Value (instance you give to Given this, your choices -- if you want to use |
Beta Was this translation helpful? Give feedback.
Ok, so this:
would work without default typing only if
@JsonTypeInfo
(with appropriate settings) was added to "val programme".Or with Default Typing if
java.lang.Object
is included (which includes mostDefaultTyping
cases).