Closed geysernrd closed 1 year ago
This is indeed an intentional change, see the release notes. You can support your use case by setting DefaultIgnoreCondition = WhenWritingNull
on your JsonSerializerOptions
.
I'll look into updating the documentation for allowNullFields
accordingly.
Got it, thanks @Tarmil!
In prior versions, this dummy example would result in "testThing" being set to a "Thing" with "stringOption" equal to None:
In v1.0, this error occurs instead: "System.Text.Json.JsonException: Missing field for record type FSI_0006+Thing: stringOption"
Granted, I can see a debate between interpreting missing data as "None" vs. interpreting it as malformed data. But a big reason I chose SystemTextJson for my use case was the ability to rapidly respond to website feature additions with new optional data fields, without having to manually edit serialized production JSON. In other words, this is a showstopper.
If the change was intentional, might it be possible to reintroduce interpreting a missing value as "None"; e.g., as a non-default option? (Apologies if this already exists; I didn't see it in the documentation. Based on the description of the allowNullFields attribute, it seems like the code above still ought to work, regardless of how allowNullFields is set.)