Hey all how do i correctly update my json SerializerSettings in my netcoreapp 3.1 application? Im trying to update this setting in the startup.cs I've tried to set this two ways, by using AddController()
and also AddMvc()
builder.Services
.AddControllers()
.AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; })
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});
builder.Services
.AddMvc()
.AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; })
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});
I don't think it's being applied correctly as I've tried to create unit tests by adding some null values to my JSON file however null reference exceptions are still being thrown, I tried to create a var json = new JsonSerializer()
so i could view the serializer settings and i could still see the NullValueHandling = Included.