-
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 JsonNumberHandling(Attribute) & support for (de)serializing numbe…
…rs from/to string (#39363) * Add JsonNumberHandling & support for (de)serializing numbers from/to string * Add JsonNumberHandlingAttribute * Address review feedback + fixups * Address review feedback ii
- Loading branch information
Showing
64 changed files
with
2,502 additions
and
147 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
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
30 changes: 30 additions & 0 deletions
30
...em.Text.Json/src/System/Text/Json/Serialization/Attributes/JsonNumberHandlingAttribute.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,30 @@ | ||
// 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, property, or field, indicates what <see cref="JsonNumberHandling"/> | ||
/// settings should be used when serializing or deserialing numbers. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | ||
public sealed class JsonNumberHandlingAttribute : JsonAttribute | ||
{ | ||
/// <summary> | ||
/// Indicates what settings should be used when serializing or deserialing numbers. | ||
/// </summary> | ||
public JsonNumberHandling Handling { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="JsonNumberHandlingAttribute"/>. | ||
/// </summary> | ||
public JsonNumberHandlingAttribute(JsonNumberHandling handling) | ||
{ | ||
if (!JsonSerializer.IsValidNumberHandlingValue(handling)) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(handling)); | ||
} | ||
Handling = handling; | ||
} | ||
} | ||
} |
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.