I have following classes:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes(
JsonSubTypes.Type(value = Speech::class, name = "Speech"),
JsonSubTypes.Type(value = Audio::class, name = "Audio"),
)
sealed class AudioItem
data class Speech(val type: String = "Speech", val contentType: String = "SSML", val content: String) : AudioItem()
data class Audio(val type: String = "Audio", val source: String) : AudioItem()
When I try to convert generic ArrayList
:
to AudioItem
val audio: List<AudioItem> = ObjectMapper().findAndRegisterModules().convertValue(a)
I get:
Cannot construct instance of
AudioItem
(no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information