From ddc0e0ad36fc6e5e75852c57722bf9425b405398 Mon Sep 17 00:00:00 2001 From: Giovanna Ribeiro Date: Wed, 24 Sep 2025 17:17:53 -0700 Subject: [PATCH] uses memory stream for serialization --- src/Core/Resolvers/QueryExecutor.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Core/Resolvers/QueryExecutor.cs b/src/Core/Resolvers/QueryExecutor.cs index 908c1bb1e8..17a485c910 100644 --- a/src/Core/Resolvers/QueryExecutor.cs +++ b/src/Core/Resolvers/QueryExecutor.cs @@ -589,8 +589,17 @@ public async Task GetJsonArrayAsync( { if (dbResultSetRow.Columns.Count > 0) { - JsonElement result = - JsonSerializer.Deserialize(JsonSerializer.Serialize(dbResultSetRow.Columns)); + // Use a memory stream to serialize the columns + using MemoryStream ms = new(); + using (Utf8JsonWriter writer = new(ms)) + { + JsonSerializer.Serialize(writer, dbResultSetRow.Columns); + } + + ms.Position = 0; + using JsonDocument doc = JsonDocument.Parse(ms); + JsonElement result = doc.RootElement.Clone(); + // FromJsonElement() added to address .NET8 regression where the .Add() throws: // System.InvalidOperationException: "The element cannot be an object or array." resultArray.Add(FromJsonElement(result));