Is it true that Kotlinx Serialization leaves a value out of json if it == it's default value?
dave08
02/26/2023, 4:29 PM
Like:
Copy code
data class Foo(val name: String, val bl: Boolean = true)
val foo = Foo("bar", true)
// Becomes:
// { "name": "bar" } not { "name": "bar", "bl": true }?
a
Adam S
02/26/2023, 5:02 PM
yes
Default values are not encoded by default in JSON. This behavior is motivated by the fact that in most real-life scenarios such configuration reduces visual clutter, and saves the amount of data being serialized.