From d46f0457ef28f7c7d57f9e2ae6c3c536c84f47ec Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Wed, 15 Oct 2025 20:17:33 +0100 Subject: [PATCH] correct issue with some commands god dam json converter has issues converting UUIDs --- SecondBotEvents/Services/CommandsService.cs | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/SecondBotEvents/Services/CommandsService.cs b/SecondBotEvents/Services/CommandsService.cs index 91ac5e9..a9d77f9 100644 --- a/SecondBotEvents/Services/CommandsService.cs +++ b/SecondBotEvents/Services/CommandsService.cs @@ -11,6 +11,7 @@ using System.Reflection; using System.Text; using System.Text.Encodings.Web; using System.Text.Json; +using System.Text.Json.Serialization; namespace SecondBotEvents.Services { @@ -611,12 +612,39 @@ namespace SecondBotEvents.Services } } + public class UUIDJsonConverter : JsonConverter + { + public override UUID Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + // Read UUID from string + return new UUID(reader.GetString()); + } + + public override void Write(Utf8JsonWriter writer, UUID value, JsonSerializerOptions options) + { + // Write UUID as string + writer.WriteStringValue(value.ToString()); + } + + // For dictionary key support + public override UUID ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return new UUID(reader.GetString()); + } + + public override void WriteAsPropertyName(Utf8JsonWriter writer, UUID value, JsonSerializerOptions options) + { + writer.WritePropertyName(value.ToString()); + } + } + public static class JsonOptions { public static readonly JsonSerializerOptions UnsafeRelaxed = new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, IncludeFields = true, + Converters = { new UUIDJsonConverter() } }; } }