|
@@ -19,56 +19,70 @@ namespace MediaBrowser.Common.Json
|
|
/// </summary>
|
|
/// </summary>
|
|
public const string CamelCaseMediaType = "application/json; profile=\"CamelCase\"";
|
|
public const string CamelCaseMediaType = "application/json; profile=\"CamelCase\"";
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// When changing these options, update
|
|
|
|
+ /// Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
|
|
|
|
+ /// -> AddJellyfinApi
|
|
|
|
+ /// -> AddJsonOptions.
|
|
|
|
+ /// </summary>
|
|
|
|
+ private static readonly JsonSerializerOptions _jsonSerializerOptions = new ()
|
|
|
|
+ {
|
|
|
|
+ ReadCommentHandling = JsonCommentHandling.Disallow,
|
|
|
|
+ WriteIndented = false,
|
|
|
|
+ DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
|
|
|
+ NumberHandling = JsonNumberHandling.AllowReadingFromString,
|
|
|
|
+ Converters =
|
|
|
|
+ {
|
|
|
|
+ new JsonGuidConverter(),
|
|
|
|
+ new JsonVersionConverter(),
|
|
|
|
+ new JsonStringEnumConverter(),
|
|
|
|
+ new JsonNullableStructConverterFactory(),
|
|
|
|
+ new JsonBoolNumberConverter(),
|
|
|
|
+ new JsonDateTimeConverter()
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ private static readonly JsonSerializerOptions _pascalCaseJsonSerializerOptions = new (_jsonSerializerOptions)
|
|
|
|
+ {
|
|
|
|
+ PropertyNamingPolicy = null
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ private static readonly JsonSerializerOptions _camelCaseJsonSerializerOptions = new (_jsonSerializerOptions)
|
|
|
|
+ {
|
|
|
|
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
|
|
+ };
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets the default <see cref="JsonSerializerOptions" /> options.
|
|
/// Gets the default <see cref="JsonSerializerOptions" /> options.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <remarks>
|
|
- /// When changing these options, update
|
|
|
|
- /// Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
|
|
|
|
- /// -> AddJellyfinApi
|
|
|
|
- /// -> AddJsonOptions.
|
|
|
|
|
|
+ /// The return value must not be modified.
|
|
|
|
+ /// If the defaults must be modified the author must use the copy constructor.
|
|
/// </remarks>
|
|
/// </remarks>
|
|
/// <returns>The default <see cref="JsonSerializerOptions" /> options.</returns>
|
|
/// <returns>The default <see cref="JsonSerializerOptions" /> options.</returns>
|
|
public static JsonSerializerOptions GetOptions()
|
|
public static JsonSerializerOptions GetOptions()
|
|
- {
|
|
|
|
- var options = new JsonSerializerOptions
|
|
|
|
- {
|
|
|
|
- ReadCommentHandling = JsonCommentHandling.Disallow,
|
|
|
|
- WriteIndented = false,
|
|
|
|
- DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
|
|
|
- NumberHandling = JsonNumberHandling.AllowReadingFromString
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- options.Converters.Add(new JsonGuidConverter());
|
|
|
|
- options.Converters.Add(new JsonVersionConverter());
|
|
|
|
- options.Converters.Add(new JsonStringEnumConverter());
|
|
|
|
- options.Converters.Add(new JsonNullableStructConverterFactory());
|
|
|
|
- options.Converters.Add(new JsonBoolNumberConverter());
|
|
|
|
- options.Converters.Add(new JsonDateTimeConverter());
|
|
|
|
-
|
|
|
|
- return options;
|
|
|
|
- }
|
|
|
|
|
|
+ => _jsonSerializerOptions;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets camelCase json options.
|
|
/// Gets camelCase json options.
|
|
/// </summary>
|
|
/// </summary>
|
|
|
|
+ /// <remarks>
|
|
|
|
+ /// The return value must not be modified.
|
|
|
|
+ /// If the defaults must be modified the author must use the copy constructor.
|
|
|
|
+ /// </remarks>
|
|
/// <returns>The camelCase <see cref="JsonSerializerOptions" /> options.</returns>
|
|
/// <returns>The camelCase <see cref="JsonSerializerOptions" /> options.</returns>
|
|
public static JsonSerializerOptions GetCamelCaseOptions()
|
|
public static JsonSerializerOptions GetCamelCaseOptions()
|
|
- {
|
|
|
|
- var options = GetOptions();
|
|
|
|
- options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
|
|
|
- return options;
|
|
|
|
- }
|
|
|
|
|
|
+ => _camelCaseJsonSerializerOptions;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets PascalCase json options.
|
|
/// Gets PascalCase json options.
|
|
/// </summary>
|
|
/// </summary>
|
|
|
|
+ /// <remarks>
|
|
|
|
+ /// The return value must not be modified.
|
|
|
|
+ /// If the defaults must be modified the author must use the copy constructor.
|
|
|
|
+ /// </remarks>
|
|
/// <returns>The PascalCase <see cref="JsonSerializerOptions" /> options.</returns>
|
|
/// <returns>The PascalCase <see cref="JsonSerializerOptions" /> options.</returns>
|
|
public static JsonSerializerOptions GetPascalCaseOptions()
|
|
public static JsonSerializerOptions GetPascalCaseOptions()
|
|
- {
|
|
|
|
- var options = GetOptions();
|
|
|
|
- options.PropertyNamingPolicy = null;
|
|
|
|
- return options;
|
|
|
|
- }
|
|
|
|
|
|
+ => _pascalCaseJsonSerializerOptions;
|
|
}
|
|
}
|
|
}
|
|
}
|