-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add [JsonConstructor] and support for deserializing with parameterize…
…d ctors (#33444) * Add [JsonConstructor] and support for deserializing with parameterized ctors * Add some more tests and clean up * Move property and parameter caches from converter to JsonClassInfo * Address review feedback * Address review feedback and reduce regression for existing benchmarks * Address review feedback and add more tests * Clean up arg state on ReadStack
- Loading branch information
Showing
50 changed files
with
6,684 additions
and
515 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
35 changes: 35 additions & 0 deletions
35
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ArgumentState.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
|
||
using FoundProperties = System.ValueTuple<System.Text.Json.JsonPropertyInfo, System.Text.Json.JsonReaderState, long, byte[]?, string?>; | ||
using FoundPropertiesAsync = System.ValueTuple<System.Text.Json.JsonPropertyInfo, object?, string?>; | ||
|
||
namespace System.Text.Json | ||
{ | ||
/// <summary> | ||
/// Holds relevant state when deserializing objects with parameterized constructors. | ||
/// Lives on the current ReadStackFrame. | ||
/// </summary> | ||
internal class ArgumentState | ||
{ | ||
// Cache for parsed constructor arguments. | ||
public object Arguments = null!; | ||
|
||
// When deserializing objects with parameterized ctors, the properties we find on the first pass. | ||
public FoundProperties[]? FoundProperties; | ||
|
||
// When deserializing objects with parameterized ctors asynchronously, the properties we find on the first pass. | ||
public FoundPropertiesAsync[]? FoundPropertiesAsync; | ||
public int FoundPropertyCount; | ||
|
||
// Current constructor parameter value. | ||
public JsonParameterInfo? JsonParameterInfo; | ||
|
||
// For performance, we order the parameters by the first deserialize and PropertyIndex helps find the right slot quicker. | ||
public int ParameterIndex; | ||
public List<ParameterRef>? ParameterRefCache; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Arguments.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace System.Text.Json | ||
{ | ||
/// <summary> | ||
/// Constructor arguments for objects with parameterized ctors with less than 5 parameters. | ||
/// This is to avoid boxing for small, immutable objects. | ||
/// </summary> | ||
internal sealed class Arguments<TArg0, TArg1, TArg2, TArg3> | ||
{ | ||
public TArg0 Arg0 = default!; | ||
public TArg1 Arg1 = default!; | ||
public TArg2 Arg2 = default!; | ||
public TArg3 Arg3 = default!; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.