Can someone help me with this? <https://stackoverf...
# serialization
a
k
If you fully control the code, can you change it to
KType
in
SomeClass.version
, so you can use
serializer(type: KType)
?
a
Yes I fully control the code. Can you explain this a bit more? How can i create a serializer from
KType
? And how can I use that serializer to decode my json?
k
getSomeObject()
Copy code
fun getSomeObject(json: String, type: KType): SomeClass {
    return Json.decodeFromString(serializer(type), json) as SomeClass
}
in
SomeClass
Copy code
val versions = arrayOf(typeOf<ClassV1>(), typeOf<ClassV2>())
Now there is also
KClass.serializer()
but I am not sure if you are supposed to use it
👍 1