mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Don't recreate JsonSerializerOptions every time
This commit is contained in:
parent
ee03b919f9
commit
9f567e6471
@ -9,6 +9,8 @@ namespace MediaBrowser.Common.Json
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class JsonDefaults
|
public static class JsonDefaults
|
||||||
{
|
{
|
||||||
|
private static JsonSerializerOptions _defaultOptions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the default <see cref="JsonSerializerOptions" /> options.
|
/// Gets the default <see cref="JsonSerializerOptions" /> options.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -21,20 +23,26 @@ namespace MediaBrowser.Common.Json
|
|||||||
/// <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
|
if (_defaultOptions == null)
|
||||||
{
|
{
|
||||||
ReadCommentHandling = JsonCommentHandling.Disallow,
|
var options = new JsonSerializerOptions
|
||||||
WriteIndented = false
|
{
|
||||||
};
|
ReadCommentHandling = JsonCommentHandling.Disallow,
|
||||||
|
WriteIndented = false
|
||||||
|
};
|
||||||
|
|
||||||
options.Converters.Add(new JsonGuidConverter());
|
options.Converters.Add(new JsonGuidConverter());
|
||||||
options.Converters.Add(new JsonInt32Converter());
|
options.Converters.Add(new JsonInt32Converter());
|
||||||
options.Converters.Add(new JsonStringEnumConverter());
|
options.Converters.Add(new JsonStringEnumConverter());
|
||||||
options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
|
options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
|
||||||
options.Converters.Add(new JsonInt64Converter());
|
options.Converters.Add(new JsonInt64Converter());
|
||||||
options.Converters.Add(new JsonDoubleConverter());
|
options.Converters.Add(new JsonDoubleConverter());
|
||||||
|
|
||||||
return options;
|
_defaultOptions = options;
|
||||||
|
return _defaultOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _defaultOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user