Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
Add JsonNumberHandling.AllowReadingFromString as a JsonSerializer web default#41539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3 src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/JsonContent.cs
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
22 changes: 18 additions & 4 deletions
22 src/libraries/System.Net.Http.Json/tests/FunctionalTests/HttpClientJsonExtensionsTests.cs
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
14 changes: 11 additions & 3 deletions
14 src/libraries/System.Net.Http.Json/tests/FunctionalTests/HttpContentJsonExtensionsTests.cs
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
23 changes: 15 additions & 8 deletions
23 src/libraries/System.Net.Http.Json/tests/FunctionalTests/TestClasses.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Xunit; | ||
| @@ -32,16 +31,23 @@ public string Serialize(JsonSerializerOptions options = null) | ||
| { | ||
| return JsonSerializer.Serialize(this, options); | ||
| } | ||
| public string SerializeWithNumbersAsStrings(JsonSerializerOptions options = null) | ||
| { | ||
| options ??= new JsonSerializerOptions(); | ||
| options.NumberHandling = options.NumberHandling | JsonNumberHandling.WriteAsString; | ||
| return JsonSerializer.Serialize(this, options); | ||
| } | ||
| } | ||
| internal static class JsonOptions | ||
| { | ||
| public static readonly JsonSerializerOptions DefaultSerializerOptions | ||
| = new JsonSerializerOptions | ||
| { | ||
| PropertyNameCaseInsensitive = true, | ||
| PropertyNamingPolicy = JsonNamingPolicy.CamelCase | ||
| }; | ||
| public static readonly JsonSerializerOptions DefaultSerializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web); | ||
layomia marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| public static readonly JsonSerializerOptions DefaultSerializerOptions_StrictNumberHandling = new JsonSerializerOptions(DefaultSerializerOptions) | ||
| { | ||
| NumberHandling = JsonNumberHandling.Strict | ||
| }; | ||
| } | ||
| internal class EnsureDefaultOptionsConverter : JsonConverter<EnsureDefaultOptions> | ||
| @@ -68,7 +74,8 @@ public override void Write(Utf8JsonWriter writer, EnsureDefaultOptions value, Js | ||
| private static void AssertDefaultOptions(JsonSerializerOptions options) | ||
| { | ||
| Assert.True(options.PropertyNameCaseInsensitive); | ||
| Assert.Equal(JsonNamingPolicy.CamelCase, options.PropertyNamingPolicy); | ||
| Assert.Same(JsonNamingPolicy.CamelCase, options.PropertyNamingPolicy); | ||
| Assert.Equal(JsonNumberHandling.AllowReadingFromString, options.NumberHandling); | ||
| } | ||
| } | ||
1 change: 1 addition & 0 deletions
1 src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
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
4 changes: 2 additions & 2 deletions
4 src/libraries/System.Text.Json/tests/Serialization/OptionsTests.cs
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
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.
Uh oh!
There was an error while loading. Please reload this page.