Hello, could anyone help with explaining why is th...
# serialization
k
Hello, could anyone help with explaining why is this different?
Copy code
@Serializable
data class Foo(
    val list: List<String> = emptyList()
)
val foo = Json.encodeToString(Foo())
println(foo)
prints
Copy code
{}
but this implementation:
Copy code
@Serializable
data class Foo(
    val list: List<String>
)
val foo = Json.encodeToString(Foo(emptyList()))
println(foo)
prints
Copy code
{
  "list": []
}
I have no idea why it’s not
Copy code
{
  "list": []
}
in both cases
j
Because values matching the default value are not serialized. I believe you can disable this on the
Json
configuration, though.
🙏 2