< Summary - Jellyfin

Information
Class: Jellyfin.Extensions.Json.JsonDefaults
Assembly: Jellyfin.Extensions
File(s): /srv/git/jellyfin/src/Jellyfin.Extensions/Json/JsonDefaults.cs
Line coverage
100%
Covered lines: 31
Uncovered lines: 0
Coverable lines: 31
Total lines: 93
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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
.cctor()100%11100%
get_Options()100%11100%
get_CamelCaseOptions()100%11100%
get_PascalCaseOptions()100%11100%

File(s)

/srv/git/jellyfin/src/Jellyfin.Extensions/Json/JsonDefaults.cs

#LineLine coverage
 1using System.Text.Json;
 2using System.Text.Json.Serialization;
 3using System.Text.Json.Serialization.Metadata;
 4using Jellyfin.Extensions.Json.Converters;
 5
 6namespace Jellyfin.Extensions.Json
 7{
 8    /// <summary>
 9    /// Helper class for having compatible JSON throughout the codebase.
 10    /// </summary>
 11    public static class JsonDefaults
 12    {
 13        /// <summary>
 14        /// Pascal case json profile media type.
 15        /// </summary>
 16        public const string PascalCaseMediaType = "application/json; profile=\"PascalCase\"";
 17
 18        /// <summary>
 19        /// Camel case json profile media type.
 20        /// </summary>
 21        public const string CamelCaseMediaType = "application/json; profile=\"CamelCase\"";
 22
 23        /// <summary>
 24        /// When changing these options, update
 25        ///  Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
 26        ///   -> AddJellyfinApi
 27        ///    -> AddJsonOptions.
 28        /// </summary>
 529        private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
 530        {
 531            ReadCommentHandling = JsonCommentHandling.Disallow,
 532            WriteIndented = false,
 533            DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
 534            NumberHandling = JsonNumberHandling.AllowReadingFromString,
 535            Converters =
 536            {
 537                new JsonGuidConverter(),
 538                new JsonNullableGuidConverter(),
 539                new JsonVersionConverter(),
 540                new JsonFlagEnumConverterFactory(),
 541                new JsonDefaultStringEnumConverterFactory(),
 542                new JsonStringEnumConverter(),
 543                new JsonNullableStructConverterFactory(),
 544                new JsonDateTimeConverter(),
 545                new JsonStringConverter()
 546            },
 547            TypeInfoResolver = new DefaultJsonTypeInfoResolver()
 548        };
 49
 550        private static readonly JsonSerializerOptions _pascalCaseJsonSerializerOptions = new(_jsonSerializerOptions)
 551        {
 552            PropertyNamingPolicy = null
 553        };
 54
 555        private static readonly JsonSerializerOptions _camelCaseJsonSerializerOptions = new(_jsonSerializerOptions)
 556        {
 557            PropertyNamingPolicy = JsonNamingPolicy.CamelCase
 558        };
 59
 60        /// <summary>
 61        /// Gets the default <see cref="JsonSerializerOptions" /> options.
 62        /// </summary>
 63        /// <remarks>
 64        /// The return value must not be modified.
 65        /// If the defaults must be modified the author must use the copy constructor.
 66        /// </remarks>
 67        /// <returns>The default <see cref="JsonSerializerOptions" /> options.</returns>
 68        public static JsonSerializerOptions Options
 165269            => _jsonSerializerOptions;
 70
 71        /// <summary>
 72        /// Gets camelCase json options.
 73        /// </summary>
 74        /// <remarks>
 75        /// The return value must not be modified.
 76        /// If the defaults must be modified the author must use the copy constructor.
 77        /// </remarks>
 78        /// <returns>The camelCase <see cref="JsonSerializerOptions" /> options.</returns>
 79        public static JsonSerializerOptions CamelCaseOptions
 2280            => _camelCaseJsonSerializerOptions;
 81
 82        /// <summary>
 83        /// Gets PascalCase json options.
 84        /// </summary>
 85        /// <remarks>
 86        /// The return value must not be modified.
 87        /// If the defaults must be modified the author must use the copy constructor.
 88        /// </remarks>
 89        /// <returns>The PascalCase <see cref="JsonSerializerOptions" /> options.</returns>
 90        public static JsonSerializerOptions PascalCaseOptions
 4491            => _pascalCaseJsonSerializerOptions;
 92    }
 93}