You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
3 years ago
|
using System;
|
||
4 years ago
|
using System.Text.Json;
|
||
|
using System.Text.Json.Serialization;
|
||
|
|
||
3 years ago
|
namespace MediaBrowser.Providers.Plugins.Omdb
|
||
4 years ago
|
{
|
||
|
/// <summary>
|
||
|
/// Converts a string <c>N/A</c> to <c>string.Empty</c>.
|
||
|
/// </summary>
|
||
4 years ago
|
public class JsonOmdbNotAvailableStringConverter : JsonConverter<string?>
|
||
4 years ago
|
{
|
||
|
/// <inheritdoc />
|
||
4 years ago
|
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||
4 years ago
|
{
|
||
4 years ago
|
if (reader.TokenType == JsonTokenType.Null)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
|
||
4 years ago
|
if (reader.TokenType == JsonTokenType.String)
|
||
|
{
|
||
4 years ago
|
// GetString can't return null here because we already handled it above
|
||
|
var str = reader.GetString()!;
|
||
|
if (str.Equals("N/A", StringComparison.OrdinalIgnoreCase))
|
||
4 years ago
|
{
|
||
|
return null;
|
||
|
}
|
||
4 years ago
|
|
||
|
return str;
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
return JsonSerializer.Deserialize<string?>(ref reader, options);
|
||
4 years ago
|
}
|
||
|
|
||
|
/// <inheritdoc />
|
||
4 years ago
|
public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options)
|
||
4 years ago
|
{
|
||
4 years ago
|
writer.WriteStringValue(value);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|