From 4b880e81ca25463565ca76fc41c4ba6bde4a4386 Mon Sep 17 00:00:00 2001 From: Velvet Toroyashi <42438262+VelvetToroyashi@users.noreply.github.com> Date: Fri, 10 May 2024 21:54:24 -0400 Subject: [PATCH] fix: Add converter for integration types config when writing manually --- .../Extensions/ServiceCollectionExtensions.cs | 3 +++ .../Internal/EnumKeyDictionaryConverterFactory.cs | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Backend/Remora.Discord.API/Extensions/ServiceCollectionExtensions.cs b/Backend/Remora.Discord.API/Extensions/ServiceCollectionExtensions.cs index 9e1e16b5af..081f315a7f 100644 --- a/Backend/Remora.Discord.API/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/Remora.Discord.API/Extensions/ServiceCollectionExtensions.cs @@ -41,6 +41,7 @@ using Remora.Discord.API.Rest; using Remora.Discord.API.VoiceGateway.Commands; using Remora.Discord.API.VoiceGateway.Events; +using Remora.Rest.Core; using Remora.Rest.Extensions; using Remora.Rest.Json; using Remora.Rest.Json.Policies; @@ -1228,6 +1229,8 @@ private static JsonSerializerOptions AddOAuth2ObjectConverters(this JsonSerializ options.AddDataObjectConverter(); + options.Converters.Insert(0, new EnumKeyDictionaryConverterFactory.EnumKeyDictionaryConverterInner(options)); + return options; } diff --git a/Backend/Remora.Discord.API/Json/Converters/Internal/EnumKeyDictionaryConverterFactory.cs b/Backend/Remora.Discord.API/Json/Converters/Internal/EnumKeyDictionaryConverterFactory.cs index 5a902f4a46..8410ad981b 100644 --- a/Backend/Remora.Discord.API/Json/Converters/Internal/EnumKeyDictionaryConverterFactory.cs +++ b/Backend/Remora.Discord.API/Json/Converters/Internal/EnumKeyDictionaryConverterFactory.cs @@ -50,18 +50,24 @@ public override bool CanConvert(Type typeToConvert) options ); - private class EnumKeyDictionaryConverterInner : JsonConverter> + /// + internal class EnumKeyDictionaryConverterInner : JsonConverter> where TEnumKey : struct, Enum { private readonly JsonConverter _valueConverter; private readonly JsonConverter _keyConverter; + /// + /// Initializes a new instance of the class. + /// + /// The serializer options. public EnumKeyDictionaryConverterInner(JsonSerializerOptions options) { _valueConverter = (JsonConverter)options.GetConverter(typeof(TValue)); _keyConverter = new StringEnumConverter(asInteger: true); } + /// public override IReadOnlyDictionary Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType != JsonTokenType.StartObject) @@ -104,6 +110,7 @@ public override IReadOnlyDictionary Read(ref Utf8JsonReader re return result; } + /// public override void Write(Utf8JsonWriter writer, IReadOnlyDictionary value, JsonSerializerOptions options) { writer.WriteStartObject();