diff options
| author | Bond_009 <bond.009@outlook.com> | 2021-12-19 02:17:32 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2021-12-19 02:20:46 +0100 |
| commit | ea9fc9f9cc3c269f55768882c631e8022ccb232d (patch) | |
| tree | caf993b9540f1b7fd78c9f1c9f29126a098eaac9 /src/Jellyfin.Extensions/Json/Converters/JsonNullableStructConverter.cs | |
| parent | 923720c988ce62ce5c57337252cf981ceeef9a23 (diff) | |
Remove unreachable branches from JsonConverters
* If the type is a reference type we don't have to handle null ourselves
* reader.ValueSpan is only valid if reader.HasValueSequence is false
Diffstat (limited to 'src/Jellyfin.Extensions/Json/Converters/JsonNullableStructConverter.cs')
| -rw-r--r-- | src/Jellyfin.Extensions/Json/Converters/JsonNullableStructConverter.cs | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/src/Jellyfin.Extensions/Json/Converters/JsonNullableStructConverter.cs b/src/Jellyfin.Extensions/Json/Converters/JsonNullableStructConverter.cs index 6de238b39..28437023f 100644 --- a/src/Jellyfin.Extensions/Json/Converters/JsonNullableStructConverter.cs +++ b/src/Jellyfin.Extensions/Json/Converters/JsonNullableStructConverter.cs @@ -15,13 +15,10 @@ namespace Jellyfin.Extensions.Json.Converters /// <inheritdoc /> public override TStruct? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (reader.TokenType == JsonTokenType.Null) - { - return null; - } - // Token is empty string. - if (reader.TokenType == JsonTokenType.String && ((reader.HasValueSequence && reader.ValueSequence.IsEmpty) || reader.ValueSpan.IsEmpty)) + if (reader.TokenType == JsonTokenType.String + && ((reader.HasValueSequence && reader.ValueSequence.IsEmpty) + || (!reader.HasValueSequence && reader.ValueSpan.IsEmpty))) { return null; } @@ -31,15 +28,6 @@ namespace Jellyfin.Extensions.Json.Converters /// <inheritdoc /> public override void Write(Utf8JsonWriter writer, TStruct? value, JsonSerializerOptions options) - { - if (value.HasValue) - { - JsonSerializer.Serialize(writer, value.Value, options); - } - else - { - writer.WriteNullValue(); - } - } + => JsonSerializer.Serialize(writer, value!.Value, options); // null got handled higher up the call stack } } |
