< 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 4/8/2026 - 12:11:47 AM Line coverage: 100% (31/31) Total lines: 93

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>
 729        private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
 730        {
 731            ReadCommentHandling = JsonCommentHandling.Disallow,
 732            WriteIndented = false,
 733            DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
 734            NumberHandling = JsonNumberHandling.AllowReadingFromString,
 735            Converters =
 736            {
 737                new JsonGuidConverter(),
 738                new JsonNullableGuidConverter(),
 739                new JsonVersionConverter(),
 740                new JsonFlagEnumConverterFactory(),
 741                new JsonDefaultStringEnumConverterFactory(),
 742                new JsonStringEnumConverter(),
 743                new JsonNullableStructConverterFactory(),
 744                new JsonDateTimeConverter(),
 745                new JsonStringConverter()
 746            },
 747            TypeInfoResolver = new DefaultJsonTypeInfoResolver()
 748        };
 49
 750        private static readonly JsonSerializerOptions _pascalCaseJsonSerializerOptions = new(_jsonSerializerOptions)
 751        {
 752            PropertyNamingPolicy = null
 753        };
 54
 755        private static readonly JsonSerializerOptions _camelCaseJsonSerializerOptions = new(_jsonSerializerOptions)
 756        {
 757            PropertyNamingPolicy = JsonNamingPolicy.CamelCase
 758        };
 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
 186869            => _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}