When storing a java object as json, @class
will be added to data and that will be used to DEserialize in to the respective object.
But when a Kotlin
data class is involved, it is not adding the @class
and when I try to deserialize ,I am getting the error
Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class java.lang.Object]: missing type id property '@class'
at [Source: (byte[])"{"Integer":1}"; line: 1, column: 13]
at com.fasterxml.jackson.databind.exc.InvalidTypeIdException.from(InvalidTypeIdException.java:43)
at com.fasterxml.jackson.databind.DeserializationContext.missingTypeIdException(DeserializationContext.java:1771)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingTypeId(DeserializationContext.java:1300)
I cannot add the annotation @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
as this would expose my data class and I understand that the error is because Kotlin data classes are final by default.
Is there any solution to overcome this error?