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

This commit is contained in:
ta264
2021-02-10 21:52:48 +00:00
parent 16b3817202
commit d3e8c7e0c9
40 changed files with 378 additions and 88 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 Readarr.Http.ClientSchema
@@ -213,9 +214,9 @@ namespace Readarr.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
{
@@ -231,9 +232,9 @@ namespace Readarr.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
{
@@ -243,7 +244,18 @@ namespace Readarr.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);
};
}
}