I have the Json shown below.
This is actually a far more complex object in reality, but this extract demonstrates my question.
I am looking at shrinking the size of the Json response being generated. This is currently being generated using the standard JsonResult in MVC,
Is there a way of getting JSonResult to not stream properties that have a value of 0? If that is possible, it would shrink my json response a lot! This in turn would make parsing faster.
{
"firstValue": 0.2000,
"secondValue": 30.80,
"thirdValue": 0.0,
"fourthValue": 30.80,
"fifthValue": 0.0
}
So I would only actually end up passing back the response below to the caller:
{
"firstValue": 0.2000,
"secondValue": 30.80,
"fourthValue": 30.80,
}
I have seen answers pointing me to using App_Start in my web api but I am using Kestrel which doesnt have an app start - this is being hosted by Service Fabric
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
new ServiceInstanceListener(
serviceContext =>
new KestrelCommunicationListener(
serviceContext,
(url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");
return new WebHostBuilder()
.UseKestrel(options => { options.Listen(IPAddress.Any, 8081); })
.ConfigureServices(
services => services
.AddSingleton(serviceContext)
.AddSingleton(new ConfigSettings(serviceContext))
.AddSingleton(new HttpClient())
.AddSingleton(new FabricClient()))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseStartup<Startup>()
.UseSerilog(_log, true)
.UseUrls(url)
.Build();
}))
};
}