Closed
Description
Background and Motivation
Adds a new option to the Newtonsoft.Json-based NuGet package for MVC to enable culture-aware deserialization of request bodies as proposed by #9994 (comment).
I missed the need to propose the API before doing the PR as I was looking at help wanted
issues, so the below is already implemented in #31331.
Proposed API
namespace Microsoft.AspNetCore.Mvc
{
public static class MvcNewtonsoftJsonOptions
{
+ public bool ReadJsonWithRequestCulture { get; set; }
}
}
Usage Examples
The application would opt-in to the behavior like so:
services.AddControllersWithViews()
.AddNewtonsoftJson(options => options.ReadJsonWithRequestCulture = true);
Which would then allow requests such as the following to succeed:
curl http://localhost:20991/api/values/date3 -X POST -d "{\"Date\":\"15\/5\/2019\"}" -H "culture: es-MX" -H "Content-Type: application/json"
Alternative Designs
None considered.
Risks
None known - new behaviour this flag would enable would be guarded behind it, with its default value being false
to retain current behaviour.