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
This commit is contained in:
Bjarke Berg
2024-04-16 16:47:58 +02:00
committed by GitHub
parent 41bbe67343
commit 36bde9e7f0
3 changed files with 14 additions and 10 deletions

View File

@@ -47,7 +47,11 @@ internal class AddGuidsToUsers : UnscopedMigrationBase
AddColumnIfNotExists<UserDto>(columns, NewColumnName);
var nodeDtoTrashedIndex = $"IX_umbracoUser_userKey";
CreateIndex<UserDto>(nodeDtoTrashedIndex);
if (IndexExists(nodeDtoTrashedIndex) is false)
{
CreateIndex<UserDto>(nodeDtoTrashedIndex);
}
List<NewUserDto>? userDtos = Database.Fetch<NewUserDto>();
if (userDtos is null)

View File

@@ -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
}
};

View File

@@ -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<string>());
var meta = firstExtension["meta"];
Assert.AreEqual("My Tree", meta["label"].GetValue<string>());
var someArray = meta["someArray"];
Assert.AreEqual(1, someArray[0].GetValue<int>());
}
[Test]