Add support for preserve references on JSON#655
Merged
jozkee merged 32 commits intodotnet:masterfrom Jan 19, 2020
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
layomia
reviewed
Dec 9, 2019
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/DefaultReferenceResolver.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/BidirectionalDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/BidirectionalDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/BidirectionalDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/DefaultReferenceResolver.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/BidirectionalDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/Serialization/ReferenceHandlingTests.Serialize.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/Serialization/ReferenceHandlingTests.Serialize.cs
Show resolved
Hide resolved
jozkee
commented
Dec 10, 2019
...ries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleObject.cs
Outdated
Show resolved
Hide resolved
* Inline ReferenceHandling logic within main methods. * remove stale Handle*Ref methods * Refactor the code for Deserialization * Create methods to reuse code * Try to isolate Preserve logic as much as I can * Replaced Exceptions for ThrowHelper methods * Remove stale condition on $ref * Add AggressiveInlining to HandlePropertyNameDefault * Inline feature code in Serialization
Add Reference EqualityComparer to Serialize dictionary.
Member
Author
|
Benchmarks results for Serialize: BenchmarkDotNet=v0.12.0, OS=Windows 10.0.18363
Intel Core i7-6700 CPU 3.40GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=5.0.100-alpha1-015718
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.19.55901, CoreFX 5.0.19.55607), X64 RyuJIT
Job-YXBSEL : .NET Core 5.0.0 (CoreCLR 5.0.19.56303, CoreFX 5.0.19.60601), X64 RyuJIT
Toolchain=CoreRun
Master
Feature
|
Member
Author
|
Benchmark results for Deserialize: Master
Feature
|
… when enumerable is already initialized.
layomia
reviewed
Dec 14, 2019
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/DefaultReferenceResolver.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/DefaultReferenceResolver.cs
Outdated
Show resolved
Hide resolved
.../System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleDictionary.cs
Outdated
Show resolved
Hide resolved
.../System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleDictionary.cs
Outdated
Show resolved
Hide resolved
...ries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleObject.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceHandling.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStackFrame.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/Serialization/ReferenceHandlingTests.Deserialize.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/Serialization/ReferenceHandlingTests.Deserialize.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/DefaultReferenceResolver.cs
Outdated
Show resolved
Hide resolved
danmoseley
reviewed
Jan 7, 2020
danmoseley
reviewed
Jan 7, 2020
* Switched ReferenceResolver to access it through a read-only property that initializes it the first time is tried to be accesed. * Renamed some methods and properties * Refactored WriteReference* methods. * Fixed Exception messages * Removed literal message comparison on tests.
* Fix issues found with Round-tripping scenarios * Move DictionaryPropertyIsPreserved to EndProperty() in order to fix issue where two dictionary properties were next to each other and the DictionaryPropertyIsPreserved was not reset. * Add ReadStackFrame.IsNestedPreservedArray in order to identify preserved arrays nested and prevent using setPropertyDirectly on them.
…enceHandlingAndNullability
Member
Author
|
There are a few non-trivial thighs left to do:
Can we move those for future (in a new issue) so we can merge? |
steveharter
reviewed
Jan 13, 2020
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/MetadataPropertyName.cs
Outdated
Show resolved
Hide resolved
* Change ReferenceResolver from class to struct to avoid one allocation. * Replace propertyName.ToArray() for constant arrays in order to avoid allocation.
steveharter
approved these changes
Jan 14, 2020
Contributor
steveharter
left a comment
There was a problem hiding this comment.
All functional concerns addressed. Thanks for all the research and work on this very important feature!
7bcf47b to
c8a4ed5
Compare
* Use PropertyCacheArray on Values property lookup. * Make Comparer static field to avoid one allocation at runtime. * Document reasoning for DefaultReferenceResolver and ReferenreEqualsEqualityComparer
c8a4ed5 to
c0befe5
Compare
ahsonkhan
reviewed
Jan 16, 2020
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/WriteStackFrame.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/System.Text.Json.Tests.csproj
Outdated
Show resolved
Hide resolved
* Add documentation to DefaultReferenceResolver public methods.
ahsonkhan
reviewed
Jan 17, 2020
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/DefaultReferenceResolver.cs
Outdated
Show resolved
Hide resolved
...braries/System.Text.Json/src/System/Text/Json/Serialization/JsonPreservableArrayReference.cs
Outdated
Show resolved
Hide resolved
...braries/System.Text.Json/src/System/Text/Json/Serialization/JsonPreservableArrayReference.cs
Show resolved
Hide resolved
...es/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleMetadata.cs
Show resolved
Hide resolved
...es/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleMetadata.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceHandling.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceHandling.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceHandling.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceHandling.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/tests/Serialization/ReferenceHandlingTests.Deserialize.cs
Outdated
Show resolved
Hide resolved
ahsonkhan
reviewed
Jan 18, 2020
| //Struct as array element (same as struct being root). | ||
| ImmutableArray.Create(employee); | ||
|
|
||
| // Regardless of using preserve, do not emit $id to value types; that is why we compare against default. |
Contributor
There was a problem hiding this comment.
This is a helpful comment.
| } | ||
|
|
||
| //NOTE: If you implement a converter, you are on your own when handling metadata properties and therefore references.Newtonsoft does the same. | ||
| //However; is there a way to recall preserved references previously found in the payload and to store new ones found in the converter's payload? that would be a cool enhancement. |
Contributor
There was a problem hiding this comment.
It sure would be a cool enhancement :)
* On $values, set PropertyName on state.Current.JsonPropertyName instead.
ahsonkhan
approved these changes
Jan 18, 2020
|
Hello @jozkee! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Member
|
@psmulovics there's an edit button in the top right if you're offering 😺 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.