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/JsonNullableGuidConverter.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/JsonNullableGuidConverter.cs')
| -rw-r--r-- | src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs b/src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs index 6192d1598..b477bcb66 100644 --- a/src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs +++ b/src/Jellyfin.Extensions/Json/Converters/JsonNullableGuidConverter.cs @@ -1,5 +1,4 @@ using System; -using System.Globalization; using System.Text.Json; using System.Text.Json.Serialization; @@ -12,21 +11,19 @@ namespace Jellyfin.Extensions.Json.Converters { /// <inheritdoc /> public override Guid? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var guidStr = reader.GetString(); - return guidStr == null ? null : new Guid(guidStr); - } + => JsonGuidConverter.ReadInternal(ref reader); /// <inheritdoc /> public override void Write(Utf8JsonWriter writer, Guid? value, JsonSerializerOptions options) { - if (value == null || value == Guid.Empty) + if (value == Guid.Empty) { writer.WriteNullValue(); } else { - writer.WriteStringValue(value.Value.ToString("N", CultureInfo.InvariantCulture)); + // null got handled higher up the call stack + JsonGuidConverter.WriteInternal(writer, value!.Value); } } } |
