-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for JsonUnmappedMemberHandling (#79945)
* Add support for JsonUnmappedMemberHandling. * Address feedback * Ignore global UnmappedMemberHandling setting when a JsonExtensionDataAttribute is specified. * Fix VerifyOptionsEqual method. * Update src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs Co-authored-by: Krzysztof Wicher <mordotymoja@gmail.com> Co-authored-by: Krzysztof Wicher <mordotymoja@gmail.com>
- Loading branch information
1 parent
5493c13
commit 870825a
Showing
29 changed files
with
638 additions
and
57 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/libraries/System.Text.Json/Common/JsonUnmappedMemberHandling.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,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Text.Json.Serialization | ||
{ | ||
/// <summary> | ||
/// Determines how <see cref="JsonSerializer"/> handles JSON properties that | ||
/// cannot be mapped to a specific .NET member when deserializing object types. | ||
/// </summary> | ||
#if BUILDING_SOURCE_GENERATOR | ||
internal | ||
#else | ||
public | ||
#endif | ||
enum JsonUnmappedMemberHandling | ||
{ | ||
/// <summary> | ||
/// Silently skips any unmapped properties. This is the default behavior. | ||
/// </summary> | ||
Skip = 0, | ||
|
||
/// <summary> | ||
/// Throws an exception when an unmapped property is encountered. | ||
/// </summary> | ||
Disallow = 1, | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...Json/src/System/Text/Json/Serialization/Attributes/JsonUnmappedMemberHandlingAttribute.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,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Text.Json.Serialization | ||
{ | ||
/// <summary> | ||
/// When placed on a type, determines the <see cref="JsonUnmappedMemberHandling"/> configuration | ||
/// for the specific type, overriding the global <see cref="JsonSerializerOptions.UnmappedMemberHandling"/> setting. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct, | ||
AllowMultiple = false, Inherited = false)] | ||
public class JsonUnmappedMemberHandlingAttribute : JsonAttribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="JsonUnmappedMemberHandlingAttribute"/>. | ||
/// </summary> | ||
public JsonUnmappedMemberHandlingAttribute(JsonUnmappedMemberHandling unmappedMemberHandling) | ||
{ | ||
UnmappedMemberHandling = unmappedMemberHandling; | ||
} | ||
|
||
/// <summary> | ||
/// Specifies the unmapped member handling setting for the attribute. | ||
/// </summary> | ||
public JsonUnmappedMemberHandling UnmappedMemberHandling { get; } | ||
} | ||
} |
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.