aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs')
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs28
1 files changed, 6 insertions, 22 deletions
diff --git a/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs b/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs
index 6c93cd13e..cd0017c78 100644
--- a/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs
+++ b/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs
@@ -1,6 +1,4 @@
using System;
-using System.Buffers;
-using System.Buffers.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
@@ -15,29 +13,15 @@ namespace MediaBrowser.Common.Json.Converters
/// <inheritdoc />
public override int? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
- if (reader.TokenType == JsonTokenType.String)
+ switch (reader.TokenType)
{
- ReadOnlySpan<byte> span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
- if (Utf8Parser.TryParse(span, out int number, out int bytesConsumed) && span.Length == bytesConsumed)
- {
- return number;
- }
-
- var stringValue = reader.GetString().AsSpan();
-
- // value is null or empty, just return null.
- if (stringValue.IsEmpty)
- {
+ case JsonTokenType.String when (reader.HasValueSequence && reader.ValueSequence.IsEmpty) || reader.ValueSpan.IsEmpty:
+ case JsonTokenType.Null:
return null;
- }
-
- if (int.TryParse(stringValue, out number))
- {
- return number;
- }
+ default:
+ // fallback to default handling
+ return reader.GetInt32();
}
-
- return reader.GetInt32();
}
/// <inheritdoc />