Use JsonSerializerDefaults instead of specifying individual options (#25747)

This lets MVC use the defaults as specified by System.Text.Json. Right now, these defaults are identical
to the two properties that were removed. However this allows MVC to pick up new S.T.J defaults in 6.0 including when
users attempt to use a 6.0 versioned package with 5.0
This commit is contained in:
Pranav K 2020-09-10 11:54:00 -07:00 committed by GitHub
parent 848f42df8e
commit 09160a779f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 9 deletions

View File

@ -12,20 +12,12 @@ namespace Microsoft.AspNetCore.Mvc
/// Gets the <see cref="System.Text.Json.JsonSerializerOptions"/> used by <see cref="SystemTextJsonInputFormatter"/> and
/// <see cref="SystemTextJsonOutputFormatter"/>.
/// </summary>
public JsonSerializerOptions JsonSerializerOptions { get; } = new JsonSerializerOptions
public JsonSerializerOptions JsonSerializerOptions { get; } = new JsonSerializerOptions(JsonSerializerDefaults.Web)
{
// 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,
};
}
}