Skip to content

Commit

Permalink
exclude null values from json
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-photo committed Oct 25, 2024
1 parent 5167cb6 commit 8f1451d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
4 changes: 2 additions & 2 deletions ninaAPI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
6 changes: 2 additions & 4 deletions ninaAPI/Utility/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
22 changes: 11 additions & 11 deletions ninaAPI/WebService/V1/EquipmentMediator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions ninaAPI/WebService/V2/EquipmentMediatorV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8f1451d

Please sign in to comment.