From 399b98b36b6111d364702b117fff3c5f21b8783a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 22 Sep 2017 02:06:54 -0400 Subject: suppress null properties in JSON responses (#336) --- src/StardewModdingAPI.Web/Startup.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/StardewModdingAPI.Web') diff --git a/src/StardewModdingAPI.Web/Startup.cs b/src/StardewModdingAPI.Web/Startup.cs index c1f03b34..2d9a95f1 100644 --- a/src/StardewModdingAPI.Web/Startup.cs +++ b/src/StardewModdingAPI.Web/Startup.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; using StardewModdingAPI.Web.Framework; namespace StardewModdingAPI.Web @@ -44,6 +45,11 @@ namespace StardewModdingAPI.Web // add support for comma-delimited parameters ArrayModelBinderProvider arrayModelBinderProvider = options.ModelBinderProviders.OfType().First(); options.ModelBinderProviders.Insert(options.ModelBinderProviders.IndexOf(arrayModelBinderProvider), new CommaDelimitedModelBinderProvider()); + }) + .AddJsonOptions(options => + { + // suppress null values in JSON responses + options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; }); } -- cgit