-
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
Support resumable serialization in NullableConverter<T> #65524
Support resumable serialization in NullableConverter<T> #65524
Conversation
Tagging subscribers to this area: @dotnet/area-system-text-json Issue DetailsMakes NullableConverter support resumable serialization, adapting an approach followed by the existing FSharpOptionConverter. Fix #65522.
|
@@ -57,7 +57,7 @@ protected static JsonConverter<TElement> GetElementConverter(JsonTypeInfo elemen | |||
|
|||
protected static JsonConverter<TElement> GetElementConverter(ref WriteStack state) | |||
{ | |||
JsonConverter<TElement> converter = (JsonConverter<TElement>)state.Current.DeclaredJsonPropertyInfo!.ConverterBase; | |||
JsonConverter<TElement> converter = (JsonConverter<TElement>)state.Current.JsonPropertyInfo!.ConverterBase; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This renames a property I should have renamed in #65224 and matches the naming convention by the equivalent property in ReadStackFrame
.
@@ -227,7 +227,7 @@ internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSeriali | |||
JsonTypeInfo originalJsonTypeInfo = state.Current.JsonTypeInfo; | |||
#endif | |||
state.Push(); | |||
Debug.Assert(TypeToConvert.IsAssignableFrom(state.Current.JsonTypeInfo.Type)); | |||
Debug.Assert(TypeToConvert == state.Current.JsonTypeInfo.Type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strengthens an assertion that should have been changed via #65224.
...es/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverter.cs
Show resolved
Hide resolved
...es/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverter.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with suggestion
namespace System.Text.Json.Serialization.Converters | ||
{ | ||
internal sealed class NullableConverter<T> : JsonConverter<T?> where T : struct | ||
{ | ||
internal override ConverterStrategy ConverterStrategy { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the ConverterStrategy is determined by the value held by Nullable? I.e. it can be Value, Object, Collection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right.
@@ -74,6 +74,29 @@ public async Task WriteNestedAsyncEnumerable_DTO<TElement>(IEnumerable<TElement> | |||
Assert.Equal(1, asyncEnumerable.TotalDisposedEnumerators); | |||
} | |||
|
|||
[Theory] | |||
[MemberData(nameof(GetAsyncEnumerableSources))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a non-IAsyncEnumerable test added that can verify a larger, nullable POCO (as a value type)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nullable POCOs still work, however they don't flow the state. This becomes more evident in the case of IAE which simply fails serialization.
Makes NullableConverter support resumable serialization, adapting an approach followed by the existing FSharpOptionConverter.
Fix #65522.