# serialization

Stylianos Gakis

03/01/2024, 11:00 PM
I see that there is
in order to ensure that during deserialization process, even if a class has a default value, the input still needs to have the field present. Is there something for the opposite, where I got a class like
Copy code
internal data class Foo(
    val bar: String,
) {
    val baz: String = "fixed_value"
and I do in fact want the serialization process for this for object
to serialize into this
Copy code
  "bar": "someInput",
  "baz": "fixed_value"
I think that
encodeDefaults = true
on my
would fix this, but that is a global setting which I am not sure I necessarily want to enforce in all other places as well.
Oh, welp, it looks like
@kotlinx.serialization.EncodeDefault(mode = ALWAYS)
is what I want actually rubber duck