Fix serialization loop
This commit is contained in:
parent
a3a31952f4
commit
c1d1b6e9f4
|
@ -8,12 +8,10 @@ namespace MediaBrowser.Common.Json.Converters
|
|||
/// <summary>
|
||||
/// Converts a string <c>N/A</c> to <c>string.Empty</c>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The resulting type.</typeparam>
|
||||
public class JsonOmdbNotAvailableStructConverter<T> : JsonConverter<T?>
|
||||
where T : struct
|
||||
public class JsonOmdbNotAvailableInt32Converter : JsonConverter<int?>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
public override int? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
|
@ -24,16 +22,23 @@ namespace MediaBrowser.Common.Json.Converters
|
|||
}
|
||||
|
||||
var converter = TypeDescriptor.GetConverter(typeToConvert);
|
||||
return (T?)converter.ConvertFromString(str);
|
||||
return (int?)converter.ConvertFromString(str);
|
||||
}
|
||||
|
||||
return JsonSerializer.Deserialize<T>(ref reader, options);
|
||||
return JsonSerializer.Deserialize<int?>(ref reader, options);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options)
|
||||
public override void Write(Utf8JsonWriter writer, int? value, JsonSerializerOptions options)
|
||||
{
|
||||
JsonSerializer.Serialize(value, options);
|
||||
if (value.HasValue)
|
||||
{
|
||||
writer.WriteNumberValue(value.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ namespace MediaBrowser.Common.Json.Converters
|
|||
/// <inheritdoc />
|
||||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
|
||||
{
|
||||
JsonSerializer.Serialize(value, options);
|
||||
writer.WriteStringValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
|
||||
_jsonOptions = new JsonSerializerOptions(JsonDefaults.GetOptions());
|
||||
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableStringConverter());
|
||||
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableStructConverter<int>());
|
||||
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableInt32Converter());
|
||||
}
|
||||
|
||||
public string Name => "The Open Movie Database";
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
|
||||
_jsonOptions = new JsonSerializerOptions(JsonDefaults.GetOptions());
|
||||
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableStringConverter());
|
||||
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableStructConverter<int>());
|
||||
_jsonOptions.Converters.Add(new JsonOmdbNotAvailableInt32Converter());
|
||||
}
|
||||
|
||||
public async Task Fetch<T>(MetadataResult<T> itemResult, string imdbId, string language, string country, CancellationToken cancellationToken)
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Jellyfin.Common.Tests.Json
|
|||
{
|
||||
_options = new JsonSerializerOptions();
|
||||
_options.Converters.Add(new JsonOmdbNotAvailableStringConverter());
|
||||
_options.Converters.Add(new JsonOmdbNotAvailableStructConverter<int>());
|
||||
_options.Converters.Add(new JsonOmdbNotAvailableInt32Converter());
|
||||
_options.NumberHandling = JsonNumberHandling.AllowReadingFromString;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user