I have the following configuration in our dotnet 6 web application, and I would like to use Json.Net serialization.
services.AddControllersWithViews(ConfigureMvcOptions)
.AddNewtonsoftJson(options =>
{
options.UseMemberCasing();
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
options.SerializerSettings.Culture = Thread.CurrentThread.CurrentCulture;
options.SerializerSettings.Error += (sender, args) => throw args.ErrorContext.Error;
});
It is not working as I expected if I try to deserialize a decimal number like this: 99 999
The number is valid in our culture settings because we are using the " " as decimal separator instead of comma.
If I directly set the CultrureInfo for Json.Net, the deserialization work as expected.
options.SerializerSettings.Culture = new CultureInfo("hu-HU");
I already checked that the Thread.CurrentThread.CurrentCulture is hungarian when the exception throw by Json.Net. (throw args.ErrorContext.Error)
What I have missed? I know that I can write a custom serialization, howerver it would be nice if I could use the Json.Net serialization. I would not use System.Text.Json (I tried anyway with the same result) because we are upgrading a dotnet 4 MVC application.