Skip to content

Commit 36bde9e

Browse files
authored
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
1 parent 41bbe67 commit 36bde9e

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/Umbraco.Infrastructure/Migrations/Upgrade/V_14_0_0/AddGuidsToUsers.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ private void MigrateSqlServer()
4747
AddColumnIfNotExists<UserDto>(columns, NewColumnName);
4848

4949
var nodeDtoTrashedIndex = $"IX_umbracoUser_userKey";
50-
CreateIndex<UserDto>(nodeDtoTrashedIndex);
50+
if (IndexExists(nodeDtoTrashedIndex) is false)
51+
{
52+
CreateIndex<UserDto>(nodeDtoTrashedIndex);
53+
}
54+
5155

5256
List<NewUserDto>? userDtos = Database.Fetch<NewUserDto>();
5357
if (userDtos is null)

src/Umbraco.Infrastructure/Serialization/SystemTextJsonSerializer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public SystemTextJsonSerializer()
2020
new JsonStringEnumConverter(),
2121
new JsonUdiConverter(),
2222
new JsonUdiRangeConverter(),
23-
// We may need to add JsonObjectConverter at some point, but for the time being things work fine without
24-
//new JsonObjectConverter()
23+
new JsonObjectConverter() // Required for block editor values
2524
}
2625
};
2726

tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/PackageManifestReaderTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text;
22
using System.Text.Json;
3+
using System.Text.Json.Nodes;
34
using Microsoft.Extensions.FileProviders;
45
using Microsoft.Extensions.Logging;
56
using Moq;
@@ -93,15 +94,15 @@ public async Task Can_Deserialize_Extensions()
9394
var first = result.First();
9495

9596
// Ensure that the extensions are deserialized as JsonElement
96-
Assert.IsTrue(first.Extensions.All(e => e is JsonElement));
97+
Assert.IsTrue(first.Extensions.All(e => e is JsonObject));
9798

9899
// Test the deserialization of the first extension to make sure we don't break the JSON parsing
99-
JsonElement firstExtension = (JsonElement)first.Extensions.First();
100-
Assert.AreEqual("tree", firstExtension.GetProperty("type").GetString());
101-
var meta = firstExtension.GetProperty("meta");
102-
Assert.AreEqual("My Tree", meta.GetProperty("label").GetString());
103-
var someArray = meta.GetProperty("someArray");
104-
Assert.AreEqual(1, someArray[0].GetInt32());
100+
JsonObject firstExtension = (JsonObject)first.Extensions.First();
101+
Assert.AreEqual("tree", firstExtension["type"].GetValue<string>());
102+
var meta = firstExtension["meta"];
103+
Assert.AreEqual("My Tree", meta["label"].GetValue<string>());
104+
var someArray = meta["someArray"];
105+
Assert.AreEqual(1, someArray[0].GetValue<int>());
105106
}
106107

107108
[Test]

0 commit comments

Comments
 (0)