I have specific Json formatting requirements in my application for example I want specific date formatting and I want null values to be ignored so I put my code in Startup.cs method configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor contextAccessor)
{
.....
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
DateFormatString = "dd/MM/yyy hh:mm:ss" ,
NullValueHandling = NullValueHandling.Ignore
};
.....
}
Here is an example of my action method
[HttpGet("[action]")]
public ActionResult GetSampleyData()
{
var model= new {StartDate=DateTime.Now, Name="test"};
return new JsonResult(model);
}
But the result is not being in the format I expected. How can I set the json settings Globally sothat all my action methods use it.