diff --git a/MediaBrowser.Common/Json/Converters/JsonNullableInt64Converter.cs b/MediaBrowser.Common/Json/Converters/JsonNullableInt64Converter.cs
deleted file mode 100644
index 38e1f8e2f1..0000000000
--- a/MediaBrowser.Common/Json/Converters/JsonNullableInt64Converter.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System;
-using System.Text.Json;
-using System.Text.Json.Serialization;
-
-namespace MediaBrowser.Common.Json.Converters
-{
- ///
- /// Converts a nullable int64 object or value to/from JSON.
- /// Required - some clients send an empty string.
- ///
- public class JsonNullableInt64Converter : JsonConverter
- {
- private readonly JsonConverter _baseJsonConverter;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The base json converter.
- public JsonNullableInt64Converter(JsonConverter baseJsonConverter)
- {
- _baseJsonConverter = baseJsonConverter;
- }
-
- ///
- public override long? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
- {
- if (reader.TokenType == JsonTokenType.String && ((reader.HasValueSequence && reader.ValueSequence.IsEmpty) || reader.ValueSpan.IsEmpty))
- {
- return null;
- }
-
- return _baseJsonConverter.Read(ref reader, typeToConvert, options);
- }
-
- ///
- public override void Write(Utf8JsonWriter writer, long? value, JsonSerializerOptions options)
- {
- _baseJsonConverter.Write(writer, value, options);
- }
- }
-}
diff --git a/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs b/MediaBrowser.Common/Json/Converters/JsonNullableStructConverter.cs
similarity index 59%
rename from MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs
rename to MediaBrowser.Common/Json/Converters/JsonNullableStructConverter.cs
index a4ecc542ea..cffc41ba34 100644
--- a/MediaBrowser.Common/Json/Converters/JsonNullableInt32Converter.cs
+++ b/MediaBrowser.Common/Json/Converters/JsonNullableStructConverter.cs
@@ -5,25 +5,28 @@ using System.Text.Json.Serialization;
namespace MediaBrowser.Common.Json.Converters
{
///
- /// Converts a nullable int32 object or value to/from JSON.
+ /// Converts a nullable struct or value to/from JSON.
/// Required - some clients send an empty string.
///
- public class JsonNullableInt32Converter : JsonConverter
+ /// The struct type.
+ public class JsonNullableStructConverter : JsonConverter
+ where T : struct
{
- private readonly JsonConverter _baseJsonConverter;
+ private readonly JsonConverter _baseJsonConverter;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The base json converter.
- public JsonNullableInt32Converter(JsonConverter baseJsonConverter)
+ public JsonNullableStructConverter(JsonConverter baseJsonConverter)
{
_baseJsonConverter = baseJsonConverter;
}
///
- public override int? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
+ // Handle empty string.
if (reader.TokenType == JsonTokenType.String && ((reader.HasValueSequence && reader.ValueSequence.IsEmpty) || reader.ValueSpan.IsEmpty))
{
return null;
@@ -33,7 +36,7 @@ namespace MediaBrowser.Common.Json.Converters
}
///
- public override void Write(Utf8JsonWriter writer, int? value, JsonSerializerOptions options)
+ public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options)
{
_baseJsonConverter.Write(writer, value, options);
}
diff --git a/MediaBrowser.Common/Json/JsonDefaults.cs b/MediaBrowser.Common/Json/JsonDefaults.cs
index bbdd1029a9..5867cd4a0c 100644
--- a/MediaBrowser.Common/Json/JsonDefaults.cs
+++ b/MediaBrowser.Common/Json/JsonDefaults.cs
@@ -35,8 +35,8 @@ namespace MediaBrowser.Common.Json
options.Converters.Add(new JsonGuidConverter());
options.Converters.Add(new JsonStringEnumConverter());
- options.Converters.Add(new JsonNullableInt32Converter(baseNullableInt32Converter));
- options.Converters.Add(new JsonNullableInt64Converter(baseNullableInt64Converter));
+ options.Converters.Add(new JsonNullableStructConverter(baseNullableInt32Converter));
+ options.Converters.Add(new JsonNullableStructConverter(baseNullableInt64Converter));
return options;
}