-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-System.Text.Jsonbugsource-generatorIndicates an issue with a source generator featureIndicates an issue with a source generator feature
Milestone
Description
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:
using System.Text.Json.Serialization;
namespace JsonSerializerNullability;
public class Model
{
public Model(Dictionary<string, object?> property) => Property = property;
public Dictionary<string, object?> Property { get; }
}
[JsonSerializable(typeof(Model))]
internal partial class MyJsonSerializerContext : JsonSerializerContext
{ }Expected behavior
No warnings should be produced
Actual behavior
Warning CS8620 Argument of type 'Dictionary<string, object>' cannot be used for parameter 'property' of type 'Dictionary<string, object?>' in 'Model.Model(Dictionary<string, object?> property)' due to differences in the nullability of reference types. JsonSerializerNullability …\MyJsonSerializerContext.Model.g.cs 25 Active
Regression?
No response
Known Workarounds
No response
Configuration
net6.0 on version 6.0.0
Other information
No response
austindrenski
Metadata
Metadata
Assignees
Labels
area-System.Text.Jsonbugsource-generatorIndicates an issue with a source generator featureIndicates an issue with a source generator feature