-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure JsonSerializer / source generator works well with required members #70945
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsThe new We should ensure JsonSerializer plays nicely with required members, in whatever way is deemed fit. What should happen, for example, if a type with required members is deserialized and those required members aren't in the payload being deserialized?
|
Related: |
This needs to be considered separately for reflection and source generated serialization:
cc @krwq |
Required members - compiler feature TL; DRFull info: https://github.com/dotnet/csharplang/blob/main/proposals/required-members.md
Current behavior without any code changes
Issues of mapping compiler required with required JSON propertiesProposal #29861 is very simple:
When we look at the compiler feature following problems occur (assuming JsonTypeInfo.CreateObject is not explicitly set by user):
Potential solutionSince 1:1 mapping compiler feature with #29861 seems rather unrealistic and tricky we can define following simplified behavior for JSON: Reflection
Source genCurrently we will need to throw. |
The new
required
members feature was recently merged into the C# 11 compiler.https://github.com/dotnet/csharplang/blob/main/proposals/required-members.md
dotnet/runtime is already being built with a version supporting it.
We should ensure JsonSerializer plays nicely with required members, in whatever way is deemed fit. What should happen, for example, if a type with required members is deserialized and those required members aren't in the payload being deserialized?
The text was updated successfully, but these errors were encountered: