Hi. Trying to deserialize cached json string to da...
# serialization
r
Hi. Trying to deserialize cached json string to data object and getting exception:
kotlinx.serialization.json.internal.JsonDecodingException: Expected class kotlinx.serialization.json.JsonObject (Kotlin reflection is not available) as the serialized body of kotlinx.serialization.Polymorphic<List>, but had class kotlinx.serialization.json.JsonArray (Kotlin reflection is not available)
Json:
[ //internal structure of json object ]
Container data class:
List<R>
Function used for deserialization:
Copy code
internal inline fun <reified R : Any> String.convertToDataClass() =
    Json {
        ignoreUnknownKeys = true
    }.decodeFromString(R::class.serializer(), this)
Code example:
"[…]".convertToDataClass<List<SomeDataClass>()
When going through Ktor pipeline everything works fine but it is breaking on attempt to deserialize the same response body cached as string to object. Any ideas how to fix this?