Kumaran Masilamani
04/21/2021, 5:37 PM//frontend code
val jsonString = JSON.stringify(dynamicData)
val myObj = JSON.parse<MyObject>(jsonString)
myService.someMethod(myObj)
//backend
This myObj is coming as "[object Object]"
and getting this error:
[reactor-http-nio-8] ERROR io.kvision.remote.KVServiceManager - Unexpected JSON token at offset 0: Expected '{, kind: CLASS'
JSON input: "[object Object]"
I have a workaround to pass the stringified json to backend and then parse as my type.
But just wanted to get some idea whether this can be done in frontend.Robert Jaros
04/21/2021, 7:00 PMMyObject
serializable?Robert Jaros
04/21/2021, 7:00 PM@Serializable
with kotlinx.serializationKumaran Masilamani
04/21/2021, 7:06 PMKumaran Masilamani
04/21/2021, 7:07 PMRobert Jaros
04/21/2021, 7:08 PMJSON
Robert Jaros
04/21/2021, 7:09 PMJSON.parse
you should use Json.decodeFromString
from kotlinx.serialization
Robert Jaros
04/21/2021, 7:13 PMio.kvision.utils.JSON.plain
(or .nostrict
) which has custom serializers for Date
class already declaredKumaran Masilamani
04/21/2021, 7:55 PMkotlinx.serialization.json.Json{ ignoreUnknownKeys = true }
.decodeFromString<MyObject>(JSON.stringify(dynamicData))
This worked.. Cheers