Is there a good way of fixing kotlinx.serializatio...
# announcements
m
Is there a good way of fixing kotlinx.serialization's handling of nullable values? This class...
Copy code
@Serializable
data class MyDataClass(
    val myProp: String?
)
... will throw
kotlinx.serialization.MissingFieldException: Field 'myProp' is required, but it was missing
if the json does not contain the
myProp
key. I really dont want to add a default value of
null
to every single optional field
n
@Optional
?
👍 1
m
Thats a good suggestion, thank you. But honestly its not much better than a null default value.... I guess im looking for a way to set it up during the instantiation of KotlinxSerializer (JsonBuilder)
I feel like defining that the property is nullable should be sufficient for it to be considered optional
n
looks like you have to provide a default value if that's the behavior you want
looks like
myProp: String? = null
is the way to go, for better or worse
m
😞
thats unfortunate but oh well... Thank you!