Skip to content

Commit

Permalink
Fix continuation of JSON deserialization (#42158)
Browse files Browse the repository at this point in the history
* Repro #42070

* formatting

* namespace

* Fix

* never forget the header

* More tests
- Test continuation at every position inside the tested object
- Many member with primitive and nullable types
- One more level of nested object
- All combinations of class/struct for tested and nested object
- tested and nested object with parametrized ctor for some properties

* Addressed feedback

* Test with original repro data from #42070

* custom converter to ensure the padding is written in front of the tested object

* rename

* test data moved to Strings.resx
  • Loading branch information
devsko authored Sep 16, 2020
1 parent 7839138 commit 6c27393
Show file tree
Hide file tree
Showing 4 changed files with 525 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public override bool ReadJsonAndSetMember(object obj, ref ReadStack state, ref U
}
else if (Converter.CanUseDirectReadOrWrite && state.Current.NumberHandling == null)
{
// CanUseDirectReadOrWrite == false when using streams
Debug.Assert(!state.IsContinuation);

if (!isNullToken || !IgnoreDefaultValuesOnRead || !Converter.CanBeNull)
{
// Optimize for internal converters by avoiding the extra call to TryRead.
Expand All @@ -234,7 +237,7 @@ public override bool ReadJsonAndSetMember(object obj, ref ReadStack state, ref U
else
{
success = true;
if (!isNullToken || !IgnoreDefaultValuesOnRead || !Converter.CanBeNull)
if (!isNullToken || !IgnoreDefaultValuesOnRead || !Converter.CanBeNull || state.IsContinuation)
{
success = Converter.TryRead(ref reader, RuntimePropertyType!, Options, ref state, out T value);
if (success)
Expand Down Expand Up @@ -284,6 +287,9 @@ public override bool ReadJsonAsObject(ref ReadStack state, ref Utf8JsonReader re
// Optimize for internal converters by avoiding the extra call to TryRead.
if (Converter.CanUseDirectReadOrWrite && state.Current.NumberHandling == null)
{
// CanUseDirectReadOrWrite == false when using streams
Debug.Assert(!state.IsContinuation);

value = Converter.Read(ref reader, RuntimePropertyType!, Options);
success = true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/System.Text.Json/tests/Resources/Strings.resx

Large diffs are not rendered by default.

Loading

0 comments on commit 6c27393

Please sign in to comment.