JSON: empty string provided for integer property: NewtonSoft Deserialization and Input Formatter Differences in 4.7.2 and ASP NET Core #25871
Unanswered
MerrittMelker
asked this question in
General
Replies: 1 comment
-
There are some pretty wide-ranging differences between ASP.NET MVC on .NET Framework 4.7.2 and ASP.NET Core 3.1.0, so it's certainly possible that the default model-binding handling for completely empty models is different. Sorry if that's inconvenient in your scenario. Are you posting this just to report the difference, or is the difference a problem that you don't have a solution for? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
HTTP POST body deserialization of:
{ "IntValue": "" }
into:
public class TestDto { public int IntValue { get; set; } }
as a controller action parameter, eg:
[HttpPost] public void Post([FromBody] TestDto value) { ...
in 4.7.2 sets the value's property, IntValue, to 0 (integer default). In ASP NET CORE 3.1.0, using NewtonSoft,
mvcBuilder.AddNewtonsoftJson(options =>,,,'
the controller action's parameter value is null. Setting
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
is not a solution. The problem here is a difference in how empty strings are interpreted.
Beta Was this translation helpful? Give feedback.
All reactions