< Summary - Jellyfin

Information
Class: Jellyfin.Extensions.Json.Converters.JsonNullableStructConverter<T>
Assembly: Jellyfin.Extensions
File(s): /srv/git/jellyfin/src/Jellyfin.Extensions/Json/Converters/JsonNullableStructConverter.cs
Line coverage
75%
Covered lines: 3
Uncovered lines: 1
Coverable lines: 4
Total lines: 30
Line coverage: 75%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Read(...)50%2.15266.66%
Write(...)100%11100%

File(s)

/srv/git/jellyfin/src/Jellyfin.Extensions/Json/Converters/JsonNullableStructConverter.cs

#LineLine coverage
 1using System;
 2using System.Text.Json;
 3using System.Text.Json.Serialization;
 4
 5namespace Jellyfin.Extensions.Json.Converters
 6{
 7    /// <summary>
 8    /// Converts a nullable struct or value to/from JSON.
 9    /// Required - some clients send an empty string.
 10    /// </summary>
 11    /// <typeparam name="TStruct">The struct type.</typeparam>
 12    public class JsonNullableStructConverter<TStruct> : JsonConverter<TStruct?>
 13        where TStruct : struct
 14    {
 15        /// <inheritdoc />
 16        public override TStruct? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 17        {
 660118            if (reader.IsEmptyString())
 19            {
 020                return null;
 21            }
 22
 660123            return JsonSerializer.Deserialize<TStruct>(ref reader, options);
 24        }
 25
 26        /// <inheritdoc />
 27        public override void Write(Utf8JsonWriter writer, TStruct? value, JsonSerializerOptions options)
 32728            => JsonSerializer.Serialize(writer, value!.Value, options); // null got handled higher up the call stack
 29    }
 30}