From d778085ba54abd34e0e67b35ba33200c9a9bad07 Mon Sep 17 00:00:00 2001 From: Qstick Date: Tue, 17 Dec 2019 21:17:25 -0500 Subject: [PATCH] Revert "Fixed: Serialize flag enum as string also" This reverts commit b0ae4e9a609b2b5f4043f11eb8575bc62bd5a0e6. --- .../Converters/EmbeddedDocumentConverter.cs | 2 +- .../Converters/NoFlagsStringEnumConverter.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core/Datastore/Converters/NoFlagsStringEnumConverter.cs diff --git a/src/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs b/src/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs index f24cc9b8b..92a634cdd 100644 --- a/src/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs +++ b/src/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs @@ -21,7 +21,7 @@ public EmbeddedDocumentConverter() WriteIndented = true }; - serializerSettings.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, true)); + serializerSettings.Converters.Add(new NoFlagsStringEnumConverter()); serializerSettings.Converters.Add(new TimeSpanConverter()); serializerSettings.Converters.Add(new UtcConverter()); diff --git a/src/NzbDrone.Core/Datastore/Converters/NoFlagsStringEnumConverter.cs b/src/NzbDrone.Core/Datastore/Converters/NoFlagsStringEnumConverter.cs new file mode 100644 index 000000000..bd30b659c --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Converters/NoFlagsStringEnumConverter.cs @@ -0,0 +1,17 @@ +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace NzbDrone.Core.Datastore.Converters +{ + public class NoFlagsStringEnumConverter : JsonConverterFactory + { + private static JsonStringEnumConverter s_stringEnumConverter = new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, false); + + public override bool CanConvert(Type typeToConvert) + => typeToConvert.IsEnum && !typeToConvert.IsDefined(typeof(FlagsAttribute), inherit: false); + + public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) + => s_stringEnumConverter.CreateConverter(typeToConvert, options); + } +}