Move int64 converter to JsonDefaults location

pull/2929/head
crobibero 5 years ago
parent 2f2bceb110
commit 341b947cde

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

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

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

Loading…
Cancel
Save