For the moment part, i would like to exclude null values from my api response, so in my startup.cs file, i have this.
services.AddMvc()
.AddJsonOptions(options =>
{
// Setup json serializer
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});
But is it possible to state that on 1 or more controllers, i actually want to include NULL values??
One option is to create custom Json result type, as described in this question: Using JSON.NET as the default JSON serializer in ASP.NET MVC 3 - is it possible?. Then you can have bool var on base controller and use it do disable null's when using custom Json
result or even pass option directly:
return Json(data, ignoreNulls: true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With