SerializerSettings.NullValueHandling is not working in .NET Core 3.0

  • Thread starter Thread starter Krishna90
  • Start date Start date
K

Krishna90

Guest
The below is not working in .Net Core 3.0


The below is the code in startup.cs

public void ConfigureServices(IServiceCollection services)
{


services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});

}

If I post an order with null value in string, its not ignored in [FromBody]

below is my swagger example:

{
"date": "2020-02-27T15:49:24.189Z",
"temperatureC": 0,
"summary": null
}


here Summary is null. When I post an order I expected the pyaload shouldn't have the Summary proerty in this.

here is my Controller code:

[HttpPost]
public ActionResult Post([FromBody] WeatherForecast body)
{
var rng = new Random();

var b = body.Date;

return null;
}


When I click on Post and debugged, summary field is present with value is null, instead of ignoring this string its sending null value.

Continue reading...
 
Back
Top