aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrobibero <cody@robibe.ro>2020-04-21 08:17:13 -0600
committercrobibero <cody@robibe.ro>2020-04-21 08:17:13 -0600
commitfe632146dcba69edeec56b850736227ff5f4c5b3 (patch)
treedfbb04a9570235e220c3a7f9a0d6166709a0cecb
parentc89dc8921ffb0ce11031e9cfb096b525d94e21b3 (diff)
Move Json Options to static class for easier access.
-rw-r--r--Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs4
-rw-r--r--Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs4
-rw-r--r--Jellyfin.Server/Models/JsonOptions.cs41
3 files changed, 45 insertions, 4 deletions
diff --git a/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs b/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs
index 433a3197d..e6ad6dfb1 100644
--- a/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs
+++ b/Jellyfin.Server/Formatters/CamelCaseJsonProfileFormatter.cs
@@ -1,4 +1,4 @@
-using System.Text.Json;
+using Jellyfin.Server.Models;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
@@ -12,7 +12,7 @@ namespace Jellyfin.Server.Formatters
/// <summary>
/// Initializes a new instance of the <see cref="CamelCaseJsonProfileFormatter"/> class.
/// </summary>
- public CamelCaseJsonProfileFormatter() : base(new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })
+ public CamelCaseJsonProfileFormatter() : base(JsonOptions.CamelCase)
{
SupportedMediaTypes.Clear();
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json;profile=\"CamelCase\""));
diff --git a/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs b/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs
index 2ed006a33..675f4c79e 100644
--- a/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs
+++ b/Jellyfin.Server/Formatters/PascalCaseJsonProfileFormatter.cs
@@ -1,4 +1,4 @@
-using System.Text.Json;
+using Jellyfin.Server.Models;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
@@ -12,7 +12,7 @@ namespace Jellyfin.Server.Formatters
/// <summary>
/// Initializes a new instance of the <see cref="PascalCaseJsonProfileFormatter"/> class.
/// </summary>
- public PascalCaseJsonProfileFormatter() : base(new JsonSerializerOptions { PropertyNamingPolicy = null })
+ public PascalCaseJsonProfileFormatter() : base(JsonOptions.PascalCase)
{
SupportedMediaTypes.Clear();
// Add application/json for default formatter
diff --git a/Jellyfin.Server/Models/JsonOptions.cs b/Jellyfin.Server/Models/JsonOptions.cs
new file mode 100644
index 000000000..fa503bc9a
--- /dev/null
+++ b/Jellyfin.Server/Models/JsonOptions.cs
@@ -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;
+ }
+ }
+ }
+}