1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-22 22:15:17 -04:00

New: Use System.Text.Json for Nancy and SignalR

This commit is contained in:
ta264
2021-02-03 21:20:06 +00:00
committed by Qstick
parent e623efefd3
commit f03dfda2f0
42 changed files with 285 additions and 89 deletions
+18 -6
View File
@@ -2,10 +2,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json.Linq;
using System.Text.Json;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Reflection;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Annotations;
namespace Radarr.Http.ClientSchema
@@ -225,9 +226,9 @@ namespace Radarr.Http.ClientSchema
{
return Enumerable.Empty<int>();
}
else if (fieldValue.GetType() == typeof(JArray))
else if (fieldValue is JsonElement e && e.ValueKind == JsonValueKind.Array)
{
return ((JArray)fieldValue).Select(s => s.Value<int>());
return e.EnumerateArray().Select(s => s.GetInt32());
}
else
{
@@ -243,9 +244,9 @@ namespace Radarr.Http.ClientSchema
{
return Enumerable.Empty<string>();
}
else if (fieldValue.GetType() == typeof(JArray))
else if (fieldValue is JsonElement e && e.ValueKind == JsonValueKind.Array)
{
return ((JArray)fieldValue).Select(s => s.Value<string>());
return e.EnumerateArray().Select(s => s.GetString());
}
else
{
@@ -255,7 +256,18 @@ namespace Radarr.Http.ClientSchema
}
else
{
return fieldValue => fieldValue;
return fieldValue =>
{
var element = fieldValue as JsonElement?;
if (element == null || !element.HasValue)
{
return null;
}
var json = element.Value.GetRawText();
return STJson.Deserialize(json, propertyType);
};
}
}