From: Steve Harter Date: Fri, 6 Aug 2021 07:05:58 +0000 (-0500) Subject: Update nullability for the value parameter in JsonConverter.Write() (#56863) X-Git-Tag: accepted/tizen/unified/20220110.054933~604 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cca4dd0e307ea823d166a95537236890e0936248;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Update nullability for the value parameter in JsonConverter.Write() (#56863) * Update nullability for the value paramter in JsonConverter.Write() * Change formatting; move XML comment * Update src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs * Update src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs Co-authored-by: Eirik Tsarpalis --- diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index 757d8d6..74e7022 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -818,7 +818,12 @@ namespace System.Text.Json.Serialization public virtual bool HandleNull { get { throw null; } } public override bool CanConvert(System.Type typeToConvert) { throw null; } public abstract T? Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options); - public abstract void Write(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options); + public abstract void Write( + System.Text.Json.Utf8JsonWriter writer, +#nullable disable + T value, +#nullable restore + System.Text.Json.JsonSerializerOptions options); } [System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)] public sealed partial class JsonExtensionDataAttribute : System.Text.Json.Serialization.JsonAttribute diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs index 564e63d..e083653 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs @@ -73,7 +73,7 @@ namespace System.Text.Json.Serialization /// and whether should be passed on deserialization. /// /// - /// The default value is for converters for value types, and for converters for reference types. + /// The default value is for converters based on value types, and for converters based on reference types. /// public virtual bool HandleNull { @@ -140,6 +140,7 @@ namespace System.Text.Json.Serialization /// The being converted. /// The being used. /// The value that was converted. + /// Note that the value of determines if the converter handles null JSON tokens. public abstract T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options); internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value) @@ -583,9 +584,14 @@ namespace System.Text.Json.Serialization /// cannot be created. /// /// The to write to. - /// The value to convert. + /// The value to convert. Note that the value of determines if the converter handles values. /// The being used. - public abstract void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options); + public abstract void Write( + Utf8JsonWriter writer, +#nullable disable // T may or may not be nullable depending on the derived type's overload. + T value, +#nullable restore + JsonSerializerOptions options); internal virtual T ReadWithQuotes(ref Utf8JsonReader reader) {