-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JSON serializer source generator produces warnings for types with nullable generic parameters #61734
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsDescriptionWhen the model type has a constructor with a generic type that has a nullable type argument, that nullability is not reproduced in the source-generated code for the JSON serializer and produces a nullability warning Reproduction StepsIn a using System.Text.Json.Serialization;
namespace JsonSerializerNullability;
public record Model
{
public Model(Dictionary<string, object?> property) => Property = property;
public Dictionary<string, object?> Property { get; }
}
[JsonSerializable(typeof(Model))]
internal partial class MyJsonSerializerContext : JsonSerializerContext
{ } Expected behaviorNo warnings should be produced Actual behavior
Regression?No response Known WorkaroundsNo response Configuration
Other informationNo response
|
Related to #59464. This is actually related to nullability of generic parameters rather than constructor arguments. When working on a fix I thought I had added tests for nullable generic parameters Lines 796 to 798 in 2b23bfa
However it turns out this was never really being tested, since our test projects have their |
* Disable nullability warnings in JSON source generator * Add testcase for #61734
Let's keep these open, given that suppressing warnings is not fundamentally addressing the issue. |
Addressed in #86334. |
Description
When the model type has a constructor with a generic type that has a nullable type argument, that nullability is not reproduced in the source-generated code for the JSON serializer and produces a nullability warning
Reproduction Steps
In a
net6.0
classlib
project:Expected behavior
No warnings should be produced
Actual behavior
Regression?
No response
Known Workarounds
No response
Configuration
net6.0
on version 6.0.0Other information
No response
The text was updated successfully, but these errors were encountered: