Move Json Options to static class for easier access.
This commit is contained in:
parent
c89dc8921f
commit
fe632146dc
|
@ -1,4 +1,4 @@
|
||||||
using System.Text.Json;
|
using Jellyfin.Server.Models;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ namespace Jellyfin.Server.Formatters
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="CamelCaseJsonProfileFormatter"/> class.
|
/// Initializes a new instance of the <see cref="CamelCaseJsonProfileFormatter"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CamelCaseJsonProfileFormatter() : base(new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })
|
public CamelCaseJsonProfileFormatter() : base(JsonOptions.CamelCase)
|
||||||
{
|
{
|
||||||
SupportedMediaTypes.Clear();
|
SupportedMediaTypes.Clear();
|
||||||
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json;profile=\"CamelCase\""));
|
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json;profile=\"CamelCase\""));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System.Text.Json;
|
using Jellyfin.Server.Models;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ namespace Jellyfin.Server.Formatters
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PascalCaseJsonProfileFormatter"/> class.
|
/// Initializes a new instance of the <see cref="PascalCaseJsonProfileFormatter"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PascalCaseJsonProfileFormatter() : base(new JsonSerializerOptions { PropertyNamingPolicy = null })
|
public PascalCaseJsonProfileFormatter() : base(JsonOptions.PascalCase)
|
||||||
{
|
{
|
||||||
SupportedMediaTypes.Clear();
|
SupportedMediaTypes.Clear();
|
||||||
// Add application/json for default formatter
|
// Add application/json for default formatter
|
||||||
|
|
41
Jellyfin.Server/Models/JsonOptions.cs
Normal file
41
Jellyfin.Server/Models/JsonOptions.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Jellyfin.Server.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Json Options.
|
||||||
|
/// </summary>
|
||||||
|
public static class JsonOptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Base Json Serializer Options.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets CamelCase json options.
|
||||||
|
/// </summary>
|
||||||
|
public static JsonSerializerOptions CamelCase
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var options = _jsonOptions;
|
||||||
|
options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets PascalCase json options.
|
||||||
|
/// </summary>
|
||||||
|
public static JsonSerializerOptions PascalCase
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var options = _jsonOptions;
|
||||||
|
options.PropertyNamingPolicy = null;
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user