And how can I make optional deletaged properties ?...
# serialization
a
And how can I make optional deletaged properties ? I'm coupling serialization with Compose and I have a
val state by mutableStateOf(MyEnum.FIRST_VALUE)
, I want to omit the field if it is equal to
MyEnum.FIRST_VALUE
as it is the default one and most used through my code, but I don't understand how 🤔 I have a custom Serialiazer and I'm encoding the value as Nullable and I've set
encodeDefaults = false
in my Json configuration, but it's still emitted and when I try to read the JSON I get this
Copy code
Exception in thread "AWT-EventQueue-0" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 8: Expected numeric literal
JSON input: [{"task":"test #1","state":null},{"task":"test #2","state":null}]
e
also https://github.com/Kotlin/kotlinx.serialization/pull/1528 merged, so there should be
@EncodeDefault
in some future release