Move int64 converter to JsonDefaults location

This commit is contained in:
crobibero 2020-05-22 10:48:01 -06:00
parent 2f2bceb110
commit 341b947cde
3 changed files with 6 additions and 7 deletions

View File

@ -4,7 +4,6 @@ using Jellyfin.Api.Auth.FirstTimeSetupOrElevatedPolicy;
using Jellyfin.Api.Auth.RequiresElevationPolicy;
using Jellyfin.Api.Constants;
using Jellyfin.Api.Controllers;
using Jellyfin.Server.Converters;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
@ -76,7 +75,6 @@ namespace Jellyfin.Server.Extensions
{
// Setting the naming policy to null leaves the property names as-is when serializing objects to JSON.
options.JsonSerializerOptions.PropertyNamingPolicy = null;
options.JsonSerializerOptions.Converters.Add(new LongToStringConverter());
})
.AddControllersAsServices();
}

View File

@ -5,16 +5,16 @@ using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Jellyfin.Server.Converters
namespace MediaBrowser.Common.Json.Converters
{
/// <summary>
/// Long to String JSON converter.
/// Javascript does not support 64-bit integers.
/// </summary>
public class LongToStringConverter : JsonConverter<long>
public class JsonInt64Converter : JsonConverter<long>
{
/// <summary>
/// Read JSON string as Long.
/// Read JSON string as int64.
/// </summary>
/// <param name="reader"><see cref="Utf8JsonReader"/>.</param>
/// <param name="type">Type.</param>
@ -25,8 +25,8 @@ namespace Jellyfin.Server.Converters
if (reader.TokenType == JsonTokenType.String)
{
// try to parse number directly from bytes
ReadOnlySpan<byte> span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
if (Utf8Parser.TryParse(span, out long number, out int bytesConsumed) && span.Length == bytesConsumed)
var span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
if (Utf8Parser.TryParse(span, out long number, out var bytesConsumed) && span.Length == bytesConsumed)
{
return number;
}

View File

@ -23,6 +23,7 @@ namespace MediaBrowser.Common.Json
options.Converters.Add(new JsonGuidConverter());
options.Converters.Add(new JsonStringEnumConverter());
options.Converters.Add(new JsonInt64Converter());
return options;
}