If I have json ```{ "id": 123 }``` how can I confi...
# serialization
s
If I have json
Copy code
{
  "id": 123
}
how can I configure serialization to automatically populate nullable values and lists in class
Copy code
data class Foo(val id: Int, val bar: String?, val foobar: List<String>)
I want json to be converted to
Copy code
Foo(id = 123, bar = null, foobar = emptyList())
a
just add default values to your data class.
data class Foo(val id: Int, val bar: String?=null, val foobar: List<String> = emptyList())
s
Right. Thats what I am currently doing. Was asking if there was any other way.
v
What other way do you have in mind? If the properties do not have default values, you have to specify values on constructing the object, so on serialization the values are set to something.
Or is what you really want to not encode the default values into the JSON? That is configurable.