-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make JSON case-insensitive Fixes: #10724 The rationale for this change is that existing .NET client code for the most part uses JSON.NET with its default settings (preserve property casing). This includes the WebAPI client - which we're encouraging everyone to use. It's not really reasonable for us to break everyone using webapi client. * Make separate options and add extension method * fixit * fix build * fix text
- Loading branch information
Showing
23 changed files
with
174 additions
and
60 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Text.Json.Serialization; | ||
using Microsoft.AspNetCore.Mvc.Formatters; | ||
|
||
namespace Microsoft.AspNetCore.Mvc | ||
{ | ||
public class JsonOptions | ||
{ | ||
/// <summary> | ||
/// Gets the <see cref="System.Text.Json.Serialization.JsonSerializerOptions"/> used by <see cref="SystemTextJsonInputFormatter"/> and | ||
/// <see cref="SystemTextJsonOutputFormatter"/>. | ||
/// </summary> | ||
public JsonSerializerOptions JsonSerializerOptions { get; } = new JsonSerializerOptions | ||
{ | ||
// Limit the object graph we'll consume to a fixed depth. This prevents stackoverflow exceptions | ||
// from deserialization errors that might occur from deeply nested objects. | ||
// This value is the same for model binding and Json.Net's serialization. | ||
MaxDepth = MvcOptions.DefaultMaxModelBindingRecursionDepth, | ||
|
||
// We're using case-insensitive because there's a TON of code that there that does uses JSON.NET's default | ||
// settings (preserve case) - including the WebAPIClient. This worked when we were using JSON.NET + camel casing | ||
// because JSON.NET is case-insensitive by default. | ||
PropertyNameCaseInsensitive = true, | ||
|
||
// Use camel casing for properties | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
}; | ||
} | ||
} |
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.