From 8f1451d8c199198e5b9dbf670c67e93252da7b3e Mon Sep 17 00:00:00 2001 From: rennmaus-coder <77056626+rennmaus-coder@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:10:28 +0200 Subject: [PATCH] exclude null values from json --- ninaAPI/Properties/AssemblyInfo.cs | 4 ++-- ninaAPI/Utility/Utility.cs | 6 ++---- ninaAPI/WebService/V1/EquipmentMediator.cs | 22 ++++++++++---------- ninaAPI/WebService/V2/EquipmentMediatorV2.cs | 22 ++++++++++---------- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/ninaAPI/Properties/AssemblyInfo.cs b/ninaAPI/Properties/AssemblyInfo.cs index c5d1198..3a207f0 100644 --- a/ninaAPI/Properties/AssemblyInfo.cs +++ b/ninaAPI/Properties/AssemblyInfo.cs @@ -6,8 +6,8 @@ // [MANDATORY] The assembly versioning //Should be incremented for each new release build of a plugin -[assembly: AssemblyVersion("2.0.0.1")] -[assembly: AssemblyFileVersion("2.0.0.1")] +[assembly: AssemblyVersion("2.0.0.2")] +[assembly: AssemblyFileVersion("2.0.0.2")] // [MANDATORY] The name of your plugin [assembly: AssemblyTitle("Advanced API")] diff --git a/ninaAPI/Utility/Utility.cs b/ninaAPI/Utility/Utility.cs index 89d56f1..edefe3d 100644 --- a/ninaAPI/Utility/Utility.cs +++ b/ninaAPI/Utility/Utility.cs @@ -184,10 +184,8 @@ public static void WriteToResponse(this IHttpContext context, string json) public static void WriteToResponse(this IHttpContext context, object json, JsonSerializerSettings settings = null) { context.Response.ContentType = MimeType.Json; - if (settings == null) - { - settings = new JsonSerializerSettings(); - } + settings ??= new JsonSerializerSettings(); + settings.NullValueHandling = NullValueHandling.Ignore; string text = JsonConvert.SerializeObject(json, settings); using (var writer = new StreamWriter(context.Response.OutputStream)) { diff --git a/ninaAPI/WebService/V1/EquipmentMediator.cs b/ninaAPI/WebService/V1/EquipmentMediator.cs index 475afaa..323b7a9 100644 --- a/ninaAPI/WebService/V1/EquipmentMediator.cs +++ b/ninaAPI/WebService/V1/EquipmentMediator.cs @@ -49,57 +49,57 @@ public static HttpResponse GetDeviceInfo(EquipmentType deviceType) { case EquipmentType.Camera: ICameraMediator cam = AdvancedAPI.Controls.Camera; - response.Response = cam.GetInfo().GetAllProperties(); + response.Response = cam.GetInfo(); return response; case EquipmentType.Focuser: IFocuserMediator focuser = AdvancedAPI.Controls.Focuser; - response.Response = focuser.GetInfo().GetAllProperties(); + response.Response = focuser.GetInfo(); return response; case EquipmentType.FlatDevice: IFlatDeviceMediator flat = AdvancedAPI.Controls.FlatDevice; - response.Response = flat.GetInfo().GetAllProperties(); + response.Response = flat.GetInfo(); return response; case EquipmentType.Dome: IDomeMediator dome = AdvancedAPI.Controls.Dome; - response.Response = dome.GetInfo().GetAllProperties(); + response.Response = dome.GetInfo(); return response; case EquipmentType.FilterWheel: IFilterWheelMediator filter = AdvancedAPI.Controls.FilterWheel; - response.Response = filter.GetInfo().GetAllProperties(); + response.Response = filter.GetInfo(); return response; case EquipmentType.Switch: ISwitchMediator switches = AdvancedAPI.Controls.Switch; - response.Response = switches.GetInfo().GetAllProperties(); + response.Response = switches.GetInfo(); return response; case EquipmentType.Guider: IGuiderMediator guider = AdvancedAPI.Controls.Guider; - response.Response = guider.GetInfo().GetAllProperties(); + response.Response = guider.GetInfo(); return response; case EquipmentType.Rotator: IRotatorMediator rotator = AdvancedAPI.Controls.Rotator; - response.Response = rotator.GetInfo().GetAllProperties(); + response.Response = rotator.GetInfo(); return response; case EquipmentType.SafetyMonitor: ISafetyMonitorMediator safety = AdvancedAPI.Controls.SafetyMonitor; - response.Response = safety.GetInfo().GetAllProperties(); + response.Response = safety.GetInfo(); return response; case EquipmentType.Mount: ITelescopeMediator telescope = AdvancedAPI.Controls.Mount; - response.Response = telescope.GetInfo().GetAllProperties(); + response.Response = telescope.GetInfo(); return response; case EquipmentType.Weather: IWeatherDataMediator weather = AdvancedAPI.Controls.Weather; - response.Response = weather.GetInfo().GetAllProperties(); + response.Response = weather.GetInfo(); return response; default: diff --git a/ninaAPI/WebService/V2/EquipmentMediatorV2.cs b/ninaAPI/WebService/V2/EquipmentMediatorV2.cs index 3c587d8..7dabe9f 100644 --- a/ninaAPI/WebService/V2/EquipmentMediatorV2.cs +++ b/ninaAPI/WebService/V2/EquipmentMediatorV2.cs @@ -41,57 +41,57 @@ public static HttpResponse GetDeviceInfo(EquipmentType deviceType) { case EquipmentType.Camera: ICameraMediator cam = AdvancedAPI.Controls.Camera; - response.Response = cam.GetInfo().GetAllProperties(); + response.Response = cam.GetInfo(); return response; case EquipmentType.Focuser: IFocuserMediator focuser = AdvancedAPI.Controls.Focuser; - response.Response = focuser.GetInfo().GetAllProperties(); + response.Response = focuser.GetInfo(); return response; case EquipmentType.FlatDevice: IFlatDeviceMediator flat = AdvancedAPI.Controls.FlatDevice; - response.Response = flat.GetInfo().GetAllProperties(); + response.Response = flat.GetInfo(); return response; case EquipmentType.Dome: IDomeMediator dome = AdvancedAPI.Controls.Dome; - response.Response = dome.GetInfo().GetAllProperties(); + response.Response = dome.GetInfo(); return response; case EquipmentType.FilterWheel: IFilterWheelMediator filter = AdvancedAPI.Controls.FilterWheel; - response.Response = filter.GetInfo().GetAllProperties(); + response.Response = filter.GetInfo(); return response; case EquipmentType.Switch: ISwitchMediator switches = AdvancedAPI.Controls.Switch; - response.Response = switches.GetInfo().GetAllProperties(); + response.Response = switches.GetInfo(); return response; case EquipmentType.Guider: IGuiderMediator guider = AdvancedAPI.Controls.Guider; - response.Response = guider.GetInfo().GetAllProperties(); + response.Response = guider.GetInfo(); return response; case EquipmentType.Rotator: IRotatorMediator rotator = AdvancedAPI.Controls.Rotator; - response.Response = rotator.GetInfo().GetAllProperties(); + response.Response = rotator.GetInfo(); return response; case EquipmentType.SafetyMonitor: ISafetyMonitorMediator safety = AdvancedAPI.Controls.SafetyMonitor; - response.Response = safety.GetInfo().GetAllProperties(); + response.Response = safety.GetInfo(); return response; case EquipmentType.Mount: ITelescopeMediator telescope = AdvancedAPI.Controls.Mount; - response.Response = telescope.GetInfo().GetAllProperties(); + response.Response = telescope.GetInfo(); return response; case EquipmentType.Weather: IWeatherDataMediator weather = AdvancedAPI.Controls.Weather; - response.Response = weather.GetInfo().GetAllProperties(); + response.Response = weather.GetInfo(); return response; default: