Skip to content

Commit 38f08f8

Browse files
Replace Newtonsoft.Json with STJ
1 parent 4252eb5 commit 38f08f8

File tree

6 files changed

+136
-146
lines changed

6 files changed

+136
-146
lines changed

src/Umbraco.Deploy.Contrib/Extensions/ArtifactMigratorCollectionBuilderExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public static class ArtifactMigratorCollectionBuilderExtensions
1515
public static ArtifactMigratorCollectionBuilder AddLegacyMigrators(this ArtifactMigratorCollectionBuilder artifactMigratorCollectionBuilder)
1616
=> artifactMigratorCollectionBuilder
1717
// Pre-values to configuration
18-
////.Append<PreValuesDataTypeArtifactJsonMigrator>()
18+
.Append<PreValuesDataTypeArtifactJsonMigrator>()
1919
// Release/expire dates to schedule
20-
////.Append<DocumentArtifactJsonMigrator>()
20+
.Append<DocumentArtifactJsonMigrator>()
2121
// Allowed at root and child content types to permissions
22-
////.Append<ContentTypeArtifactJsonMigrator>()
22+
.Append<ContentTypeArtifactJsonMigrator>()
2323
// Data types
2424
////.Append<CheckBoxListDataTypeArtifactMigrator>()
2525
////.Append<ColorPickerAliasDataTypeArtifactMigrator>()
Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
1-
//using Newtonsoft.Json.Linq;
2-
//using Umbraco.Cms.Core.Models;
3-
//using Umbraco.Cms.Core.Semver;
4-
//using Umbraco.Deploy.Infrastructure.Artifacts.Content;
5-
//using Umbraco.Deploy.Infrastructure.Migrators;
1+
using System.Text.Json.Nodes;
2+
using Umbraco.Cms.Core.Models;
3+
using Umbraco.Cms.Core.Semver;
4+
using Umbraco.Deploy.Infrastructure.Artifacts.Content;
5+
using Umbraco.Deploy.Infrastructure.Migrators;
66

7-
//namespace Umbraco.Deploy.Contrib.Migrators.Legacy;
7+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy;
88

9-
///// <summary>
10-
///// Migrates the <see cref="DocumentArtifact" /> JSON from Umbraco 7 release/expire date to schedule.
11-
///// </summary>
12-
//public class DocumentArtifactJsonMigrator : ArtifactJsonMigratorBase<DocumentArtifact>
13-
//{
14-
// /// <summary>
15-
// /// Initializes a new instance of the <see cref="DocumentArtifactJsonMigrator" /> class.
16-
// /// </summary>
17-
// public DocumentArtifactJsonMigrator()
18-
// => MaxVersion = new SemVersion(3, 0, 0);
9+
/// <summary>
10+
/// Migrates the <see cref="DocumentArtifact" /> JSON from Umbraco 7 release/expire date to schedule.
11+
/// </summary>
12+
public class DocumentArtifactJsonMigrator : ArtifactJsonMigratorBase<DocumentArtifact>
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="DocumentArtifactJsonMigrator" /> class.
16+
/// </summary>
17+
public DocumentArtifactJsonMigrator()
18+
=> MaxVersion = new SemVersion(3, 0, 0);
1919

20-
// /// <inheritdoc />
21-
// public override JToken Migrate(JToken artifactJson)
22-
// {
23-
// var schedule = new JArray();
20+
/// <inheritdoc />
21+
public override JsonNode Migrate(JsonNode artifactJson)
22+
{
23+
var schedule = new JsonArray();
2424

25-
// if (artifactJson["ReleaseDate"] is JValue releaseDate &&
26-
// releaseDate.Value is not null)
27-
// {
28-
// schedule.Add(new JObject()
29-
// {
30-
// ["Date"] = releaseDate.Value<string>(),
31-
// ["Culture"] = string.Empty,
32-
// ["Action"] = nameof(ContentScheduleAction.Release)
33-
// });
34-
// }
25+
if (artifactJson["ReleaseDate"] is JsonNode releaseDate)
26+
{
27+
schedule.Add(new JsonObject()
28+
{
29+
["Date"] = releaseDate,
30+
["Culture"] = string.Empty,
31+
["Action"] = nameof(ContentScheduleAction.Release)
32+
});
33+
}
3534

36-
// if (artifactJson["ExpireDate"] is JValue expireDate &&
37-
// expireDate.Value is not null)
38-
// {
39-
// schedule.Add(new JObject()
40-
// {
41-
// ["Date"] = expireDate,
42-
// ["Culture"] = string.Empty,
43-
// ["Action"] = nameof(ContentScheduleAction.Expire)
44-
// });
45-
// }
35+
if (artifactJson["ExpireDate"] is JsonNode expireDate)
36+
{
37+
schedule.Add(new JsonObject()
38+
{
39+
["Date"] = expireDate,
40+
["Culture"] = string.Empty,
41+
["Action"] = nameof(ContentScheduleAction.Expire)
42+
});
43+
}
4644

47-
// artifactJson["Schedule"] = schedule;
45+
artifactJson["Schedule"] = schedule;
4846

49-
// return artifactJson;
50-
// }
51-
//}
47+
return artifactJson;
48+
}
49+
}
Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
1-
//using System;
2-
//using Newtonsoft.Json.Linq;
3-
//using Umbraco.Cms.Core.Semver;
4-
//using Umbraco.Deploy.Infrastructure.Artifacts.ContentType;
5-
//using Umbraco.Deploy.Infrastructure.Migrators;
6-
//using Umbraco.Extensions;
7-
8-
//namespace Umbraco.Deploy.Contrib.Migrators.Legacy;
9-
10-
///// <summary>
11-
///// Migrates the <see cref="ContentTypeArtifactBase" /> JSON from Umbraco 7 allowed at root and child content types to permissions.
12-
///// </summary>
13-
//public class ContentTypeArtifactJsonMigrator : ArtifactJsonMigratorBase<ContentTypeArtifactBase>
14-
//{
15-
// /// <summary>
16-
// /// Initializes a new instance of the <see cref="ContentTypeArtifactJsonMigrator" /> class.
17-
// /// </summary>
18-
// public ContentTypeArtifactJsonMigrator()
19-
// => MaxVersion = new SemVersion(3, 0, 0);
20-
21-
// protected override bool CanMigrateType(Type type)
22-
// => type.Inherits<ContentTypeArtifactBase>();
23-
24-
// /// <inheritdoc />
25-
// public override JToken Migrate(JToken artifactJson)
26-
// {
27-
// var permissions = new JObject();
28-
29-
// if (artifactJson["AllowedAtRoot"] is JValue allowedAtRootValue &&
30-
// allowedAtRootValue.Value is not null)
31-
// {
32-
// permissions["AllowedAtRoot"] = allowedAtRootValue;
33-
// }
34-
35-
// if (artifactJson["AllowedChildContentTypes"] is JArray allowedChildContentTypesToken)
36-
// {
37-
// permissions["AllowedChildContentTypes"] = allowedChildContentTypesToken;
38-
// }
39-
40-
// artifactJson["Permissions"] = permissions;
41-
42-
// return artifactJson;
43-
// }
44-
//}
1+
using System;
2+
using System.Text.Json.Nodes;
3+
using Umbraco.Cms.Core.Semver;
4+
using Umbraco.Deploy.Infrastructure.Artifacts.ContentType;
5+
using Umbraco.Deploy.Infrastructure.Migrators;
6+
using Umbraco.Extensions;
7+
8+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy;
9+
10+
/// <summary>
11+
/// Migrates the <see cref="ContentTypeArtifactBase" /> JSON from Umbraco 7 allowed at root and child content types to permissions.
12+
/// </summary>
13+
public class ContentTypeArtifactJsonMigrator : ArtifactJsonMigratorBase<ContentTypeArtifactBase>
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="ContentTypeArtifactJsonMigrator" /> class.
17+
/// </summary>
18+
public ContentTypeArtifactJsonMigrator()
19+
=> MaxVersion = new SemVersion(3, 0, 0);
20+
21+
protected override bool CanMigrateType(Type type)
22+
=> type.Inherits<ContentTypeArtifactBase>();
23+
24+
/// <inheritdoc />
25+
public override JsonNode Migrate(JsonNode artifactJson)
26+
{
27+
artifactJson["Permissions"] = new JsonObject()
28+
{
29+
["AllowedAtRoot"] = artifactJson["AllowedAtRoot"],
30+
["AllowedChildContentTypes"] = artifactJson["AllowedChildContentTypes"],
31+
};
32+
33+
return artifactJson;
34+
}
35+
}

src/Umbraco.Deploy.Contrib/Migrators/Legacy/DataType/MultiNodeTreePicker2DataTypeArtifactMigrator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using Newtonsoft.Json.Linq;
2+
using System.Text.Json.Nodes;
33
using Umbraco.Cms.Core;
44
using Umbraco.Cms.Core.PropertyEditors;
55
using Umbraco.Cms.Core.Semver;
@@ -29,9 +29,9 @@ public MultiNodeTreePicker2DataTypeArtifactMigrator(PropertyEditorCollection pro
2929
protected override IDictionary<string, object?>? MigrateConfiguration(IDictionary<string, object?> configuration)
3030
{
3131
if (configuration.TryGetValue("startNode", out var startNodeValue) &&
32-
startNodeValue is JObject startNode &&
33-
startNode["id"] is JValue idValue &&
34-
(idValue.Value?.ToString() is not string id || !UdiParser.TryParse(id, out _)))
32+
startNodeValue is JsonObject startNode &&
33+
startNode["id"] is JsonValue idValue &&
34+
(idValue.TryGetValue(out string? id) is false || UdiParser.TryParse(id, out _) is false))
3535
{
3636
// Remove invalid start node ID
3737
startNode.Remove("id");

src/Umbraco.Deploy.Contrib/Migrators/Legacy/DataType/MultiNodeTreePickerDataTypeArtifactMigrator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using Newtonsoft.Json.Linq;
2+
using System.Text.Json.Nodes;
33
using Umbraco.Cms.Core;
44
using Umbraco.Cms.Core.Semver;
55
using Umbraco.Cms.Core.Serialization;
@@ -25,9 +25,9 @@ public MultiNodeTreePickerDataTypeArtifactMigrator(IConfigurationEditorJsonSeria
2525
protected override IDictionary<string, object?>? MigrateConfiguration(IDictionary<string, object?> fromConfiguration)
2626
{
2727
if (fromConfiguration.TryGetValue("startNode", out var startNodeValue) &&
28-
startNodeValue is JObject startNode &&
29-
startNode["id"] is JValue idValue &&
30-
(idValue.Value?.ToString() is not string id || !UdiParser.TryParse(id, out _)))
28+
startNodeValue is JsonObject startNode &&
29+
startNode["id"] is JsonValue idValue &&
30+
(idValue.TryGetValue(out string? id) is false || UdiParser.TryParse(id, out _) is false))
3131
{
3232
// Remove invalid start node ID
3333
startNode.Remove("id");
Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
1-
//using Newtonsoft.Json.Linq;
2-
//using Umbraco.Cms.Core.Semver;
3-
//using Umbraco.Deploy.Infrastructure.Artifacts;
4-
//using Umbraco.Deploy.Infrastructure.Migrators;
5-
//using Umbraco.Extensions;
6-
7-
//namespace Umbraco.Deploy.Contrib.Migrators.Legacy;
8-
9-
///// <summary>
10-
///// Migrates the <see cref="DataTypeArtifact" /> JSON from Umbraco 7 pre-values to configuration objects/arrays.
11-
///// </summary>
12-
//public class PreValuesDataTypeArtifactJsonMigrator : ArtifactJsonMigratorBase<DataTypeArtifact>
13-
//{
14-
// /// <summary>
15-
// /// Initializes a new instance of the <see cref="PreValuesDataTypeArtifactJsonMigrator" /> class.
16-
// /// </summary>
17-
// public PreValuesDataTypeArtifactJsonMigrator()
18-
// => MaxVersion = new SemVersion(3, 0, 0);
19-
20-
// /// <inheritdoc />
21-
// public override JToken Migrate(JToken artifactJson)
22-
// {
23-
// if (artifactJson["PreValues"] is JObject preValues)
24-
// {
25-
// var configuration = new JObject();
26-
27-
// foreach (var property in preValues.Properties())
28-
// {
29-
// var propertyValue = property.Value;
30-
31-
// // Convert pre-value serialized JSON to actual JSON objects/arrays
32-
// if (propertyValue.Type == JTokenType.String &&
33-
// propertyValue.Value<string>() is string json &&
34-
// json.DetectIsJson())
35-
// {
36-
// propertyValue = JToken.Parse(json);
37-
// }
38-
39-
// configuration.Add(property.Name, propertyValue);
40-
// }
41-
42-
// artifactJson["Configuration"] = configuration;
43-
// }
44-
45-
// return artifactJson;
46-
// }
47-
//}
1+
using System.Text.Json;
2+
using System.Text.Json.Nodes;
3+
using Umbraco.Cms.Core.Semver;
4+
using Umbraco.Deploy.Infrastructure.Artifacts;
5+
using Umbraco.Deploy.Infrastructure.Migrators;
6+
using Umbraco.Extensions;
7+
8+
namespace Umbraco.Deploy.Contrib.Migrators.Legacy;
9+
10+
/// <summary>
11+
/// Migrates the <see cref="DataTypeArtifact" /> JSON from Umbraco 7 pre-values to configuration objects/arrays.
12+
/// </summary>
13+
public class PreValuesDataTypeArtifactJsonMigrator : ArtifactJsonMigratorBase<DataTypeArtifact>
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="PreValuesDataTypeArtifactJsonMigrator" /> class.
17+
/// </summary>
18+
public PreValuesDataTypeArtifactJsonMigrator()
19+
=> MaxVersion = new SemVersion(3, 0, 0);
20+
21+
/// <inheritdoc />
22+
public override JsonNode Migrate(JsonNode artifactJson)
23+
{
24+
if (artifactJson["PreValues"] is JsonObject preValues)
25+
{
26+
var configuration = new JsonObject();
27+
28+
foreach (var preValue in preValues)
29+
{
30+
var value = preValue.Value;
31+
32+
// Convert pre-value serialized JSON to actual JSON objects/arrays
33+
if (value is JsonValue jsonValue &&
34+
jsonValue.TryGetValue(out string? json) &&
35+
json.DetectIsJson())
36+
{
37+
value = JsonNode.Parse(json);
38+
}
39+
40+
configuration.Add(preValue.Key, value);
41+
}
42+
43+
artifactJson["Configuration"] = configuration;
44+
}
45+
46+
return artifactJson;
47+
}
48+
}

0 commit comments

Comments
 (0)