hi, I have encounter a problem when trying to deco...
# serialization
m
hi, I have encounter a problem when trying to decode from string. below is the simple code snippet.
Copy code
fun tryDecode(someKClass: KClass<*>, jsonString: String) {
    ...
    // throw JsonDecodingException
    val result = json.decodeFromString(someKClass.serializer(), jsonString)
    ...
}
someKClass
in the actual scenario is retrieved from Ktor's
TypeInfo.type
. This works on most cases but got stuck when the type is something like
Map
or
List
. It throws
JsonDecodingException
(Polymorphic serializer was not found for missing class discriminator ('null')). is there any way to solve this or the only thing I can do is check whether the
someKClass
is
List
or
Map
and pass the appropriate
Serializer
such as
ListSerializer
or
MapSerializer
? my goal is trying to make it as generic as possible so I want to avoid any type checking as much as possible.