using System.Text.Json;
using System.Text.Json.Serialization;
using MediaBrowser.Common.Json.Converters;
namespace MediaBrowser.Common.Json
{
///
/// Helper class for having compatible JSON throughout the codebase.
///
public static class JsonDefaults
{
///
/// Gets the default options.
///
///
/// When changing these options, update
/// Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
/// -> AddJellyfinApi
/// -> AddJsonOptions
///
/// The default options.
public static JsonSerializerOptions GetOptions()
{
var options = new JsonSerializerOptions
{
ReadCommentHandling = JsonCommentHandling.Disallow,
WriteIndented = false
};
options.Converters.Add(new JsonGuidConverter());
options.Converters.Add(new JsonStringEnumConverter());
options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
return options;
}
///
/// Gets CamelCase json options.
///
public static JsonSerializerOptions CamelCase
{
get
{
var options = GetOptions();
options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
return options;
}
}
///
/// Gets PascalCase json options.
///
public static JsonSerializerOptions PascalCase
{
get
{
var options = GetOptions();
options.PropertyNamingPolicy = null;
return options;
}
}
}
}