System.Text.Json: Providing default value for missing properties #96714
Unanswered
florianbader
asked this question in
Ideas
Replies: 1 comment 1 reply
-
Is the type owned by you? Can you set default values in its constructor? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to implement handling of changes in my JSON schema. This includes for now adding a new property to the .NET type that is missing in an existing JSON by providing a default value.
While this would work fine with mutable types it's difficult to do with immutable records. Maybe I'm missing something but currently the only way I found is through reflection:
A
JsonConverter
doesn't work as theRead
method is not called for properties that are missing in the JSON. There is also no way to use aTypeInfoResolver
on myDocument
object for theOptions
property as theSet
delegate is also not called for missing properties in JSON.Would be nice to have some way to actually provide a default value for missing properties through a JSON contract though something like
Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions