Hi, I am trying to serialize data class and gettin...
# serialization
t
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:
It must be something stupid as usual, but I can't find it.
p
You need to tell your Json instance to encode default values, or change the value of
deviceId
from the default
☝️ 2
p
try this
Copy code
val result  = Json { encodeDefaults = true }.encodeToString(Params.serializer(), params)
t
That was it .Thank you!