I've added the following code to my Startup.cs:
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});
However, this feels like a breaking change. The main reason for adding it was to remove the need for lots of null checks against request properties everywhere in the controllers. However, it also has the effect of doing it for the reverse i.e. removing properties in the response that are null. So if I understand this correctly it will mean any other apps that currently hit the api and check the response properties for null will now break as those properties won't exist in the response when they're null.
So is there a way to conditionally set this flag by api version? I don't want to go down the route of setting it per property or somehow setting this property on all relevant controllers.