Hi, I am trying to serialize data class and getting empty object as result, I can't find out what is wrong
Copy code
@Serializable
data class Params(val deviceId: String = "someId")
val params = Params()
val result = Json.encodeToString(Params.serializer(), params)
console.log("params", params)
console.log("result ", result)
I get this result:
Tomas Kormanak
04/15/2021, 1:21 PM
It must be something stupid as usual, but I can't find it.
p
Paul Griffith
04/15/2021, 4:08 PM
You need to tell your Json instance to encode default values, or change the value of
deviceId
from the default
☝️ 2
p
Prayansh Srivastava
04/15/2021, 6:03 PM
try this
Copy code
val result = Json { encodeDefaults = true }.encodeToString(Params.serializer(), params)