EncodeDefault
Controls whether the target property is serialized when its value is equal to a default value, regardless of the format settings. Does not affect decoding and deserialization process.
Example of usage:
@Serializable
data class Foo(
@EncodeDefault(ALWAYS) val a: Int = 42,
@EncodeDefault(NEVER) val b: Int = 43,
val c: Int = 44
)
Json { encodeDefaults = false }.encodeToString((Foo()) // {"a": 42}
Json { encodeDefaults = true }.encodeToString((Foo()) // {"a": 42, "c":44}
Content copied to clipboard
See also
Types
Link copied to clipboard
Strategy for the EncodeDefault annotation.