Luc Girardin
03/22/2024, 10:42 AMList<Map<String, Any?>>
. Seems that I need to register a PolymorphicSerializer for that purpose, but I didn’t figure out how to exactly do it so that I can pass it to the encodeToString()
method to get JSON output. Would very much appreciate help!hfhbd
03/22/2024, 12:00 PMLuc Girardin
03/22/2024, 12:14 PMval listOfMap: List<Map<String, Any?>> = ...
val json = Json {
useArrayPolymorphism = true
serializersModule = SerializersModule {
polymorphic(Any::class) {
subclass(List::class, ListSerializer(PolymorphicSerializer(Any::class).nullable))
}
}
}
val serializer = ListSerializer(PolymorphicSerializer(Map::class).nullable)
println(json.encodeToString(serializer, listOfMap))
but as you can see I do not understand what I am doing and do get the following error SerializationException: Serializer for subclass 'LinkedHashMap' is not found in the polymorphic scope of 'LinkedHashMap'.