From 36bde9e7f06afe337877d54bc1ccee6139aa32ab Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 16 Apr 2024 16:47:58 +0200 Subject: [PATCH] Add JsonObjectConverter to the default serializer and make a safe check before adding index (#16067) * Do not add index if it already exists * Add the JsonObjectConverter by default. This is required by the block editor * Update test to reflect that fact we have the json object converter applied --- .../Upgrade/V_14_0_0/AddGuidsToUsers.cs | 6 +++++- .../Serialization/SystemTextJsonSerializer.cs | 3 +-- .../Manifest/PackageManifestReaderTests.cs | 15 ++++++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_14_0_0/AddGuidsToUsers.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_14_0_0/AddGuidsToUsers.cs index b6d4e39d5e..0995acfeeb 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_14_0_0/AddGuidsToUsers.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_14_0_0/AddGuidsToUsers.cs @@ -47,7 +47,11 @@ internal class AddGuidsToUsers : UnscopedMigrationBase AddColumnIfNotExists(columns, NewColumnName); var nodeDtoTrashedIndex = $"IX_umbracoUser_userKey"; - CreateIndex(nodeDtoTrashedIndex); + if (IndexExists(nodeDtoTrashedIndex) is false) + { + CreateIndex(nodeDtoTrashedIndex); + } + List? userDtos = Database.Fetch(); if (userDtos is null) diff --git a/src/Umbraco.Infrastructure/Serialization/SystemTextJsonSerializer.cs b/src/Umbraco.Infrastructure/Serialization/SystemTextJsonSerializer.cs index 033256f7a9..6d74d0cc87 100644 --- a/src/Umbraco.Infrastructure/Serialization/SystemTextJsonSerializer.cs +++ b/src/Umbraco.Infrastructure/Serialization/SystemTextJsonSerializer.cs @@ -20,8 +20,7 @@ public sealed class SystemTextJsonSerializer : SystemTextJsonSerializerBase new JsonStringEnumConverter(), new JsonUdiConverter(), new JsonUdiRangeConverter(), - // We may need to add JsonObjectConverter at some point, but for the time being things work fine without - //new JsonObjectConverter() + new JsonObjectConverter() // Required for block editor values } }; diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/PackageManifestReaderTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/PackageManifestReaderTests.cs index 1c59a920e9..e1c52d075f 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/PackageManifestReaderTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/PackageManifestReaderTests.cs @@ -1,5 +1,6 @@ using System.Text; using System.Text.Json; +using System.Text.Json.Nodes; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Logging; using Moq; @@ -93,15 +94,15 @@ public class PackageManifestReaderTests var first = result.First(); // Ensure that the extensions are deserialized as JsonElement - Assert.IsTrue(first.Extensions.All(e => e is JsonElement)); + Assert.IsTrue(first.Extensions.All(e => e is JsonObject)); // Test the deserialization of the first extension to make sure we don't break the JSON parsing - JsonElement firstExtension = (JsonElement)first.Extensions.First(); - Assert.AreEqual("tree", firstExtension.GetProperty("type").GetString()); - var meta = firstExtension.GetProperty("meta"); - Assert.AreEqual("My Tree", meta.GetProperty("label").GetString()); - var someArray = meta.GetProperty("someArray"); - Assert.AreEqual(1, someArray[0].GetInt32()); + JsonObject firstExtension = (JsonObject)first.Extensions.First(); + Assert.AreEqual("tree", firstExtension["type"].GetValue()); + var meta = firstExtension["meta"]; + Assert.AreEqual("My Tree", meta["label"].GetValue()); + var someArray = meta["someArray"]; + Assert.AreEqual(1, someArray[0].GetValue()); } [Test]