I have following data class
@Serializable
data class TestClass(
val id: Int,
val content: String)
and following possible JSONs
{"id" = "1", "content": "1" }
{"id" = "2", "content": {"subcontent1": "subvalue1"} }
{"id" = "3", "content": {"subcontent2": "subvalue2"} }
Exact structure of content is unknown and may change. Is it possible to deserialize such json into TestClass ?
If I use
Json {
ignoreUnknownKeys = true
isLenient = true
}.decodeFromString<TestClass>(inputJsonString)
I get following exception
Unexpected JSON token at offset 122: Expected string or non-null literal
Could you please provide any ideas on what is the best way to overcome this?
Do I have to write custom serializer or it can be done easier somehow?