@{
- var selectedItems = JsonConvert.SerializeObject(Model.SelectedItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
- var allItems = JsonConvert.SerializeObject(Model.AllItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
+ var selectedItems = JConvert.SerializeObject(Model.SelectedItems, JOptions.CamelCase);
+ var allItems = JConvert.SerializeObject(Model.AllItems, JOptions.CamelCase);
}
diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/PlaceholderAdminNode.Fields.TreeEdit.cshtml b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/PlaceholderAdminNode.Fields.TreeEdit.cshtml
index a7c70b08cc9..f96e014a3cf 100644
--- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/PlaceholderAdminNode.Fields.TreeEdit.cshtml
+++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/PlaceholderAdminNode.Fields.TreeEdit.cshtml
@@ -1,6 +1,6 @@
@model PlaceholderAdminNodeViewModel
-@using Newtonsoft.Json
-@using Newtonsoft.Json.Serialization
+@using System.Text.Json
+@using System.Text.Json.Nodes
@@ -63,8 +63,8 @@
@{
- var selectedItems = JsonConvert.SerializeObject(Model.SelectedItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
- var allItems = JsonConvert.SerializeObject(Model.AllItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
+ var selectedItems = JConvert.SerializeObject(Model.SelectedItems, JOptions.CamelCase);
+ var allItems = JConvert.SerializeObject(Model.AllItems, JOptions.CamelCase);
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs
index 91e12c5dca2..82805da1f4f 100644
--- a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs
@@ -28,9 +28,8 @@ public class GraphQLMiddleware
private readonly GraphQLSettings _settings;
private readonly IDocumentExecuter _executer;
internal static readonly Encoding _utf8Encoding = new UTF8Encoding(false);
- private readonly static MediaType _jsonMediaType = new("application/json");
- private readonly static MediaType _graphQlMediaType = new("application/graphql");
- private readonly static JsonSerializerOptions _jsonSerializerOptions = new() { WriteIndented = false, PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
+ private static readonly MediaType _jsonMediaType = new("application/json");
+ private static readonly MediaType _graphQlMediaType = new("application/graphql");
public GraphQLMiddleware(
RequestDelegate next,
@@ -101,7 +100,7 @@ private async Task ExecuteAsync(HttpContext context, ISchemaFactory schemaServic
}
else
{
- request = await JsonSerializer.DeserializeAsync
(context.Request.Body, _jsonSerializerOptions);
+ request = await JsonSerializer.DeserializeAsync(context.Request.Body, JOptions.CamelCase);
}
}
else
@@ -189,7 +188,7 @@ private static GraphQLRequest CreateRequestFromQueryString(HttpContext context,
if (context.Request.Query.ContainsKey("variables"))
{
- request.Variables = JsonSerializer.Deserialize(context.Request.Query["variables"], _jsonSerializerOptions);
+ request.Variables = JConvert.DeserializeObject(context.Request.Query["variables"], JOptions.CamelCase);
}
if (context.Request.Query.ContainsKey("operationName"))
diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs
index 18fd0206ab1..833546fdd66 100644
--- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.Json.Nodes;
+using System.Text.Json.Settings;
using System.Threading.Tasks;
using Fluid;
using Fluid.Values;
@@ -8,7 +10,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
-using Newtonsoft.Json.Linq;
using OrchardCore.Autoroute.Core.Indexes;
using OrchardCore.Autoroute.Models;
using OrchardCore.Autoroute.ViewModels;
@@ -70,7 +71,7 @@ public override async Task PublishedAsync(PublishContentContext context, Autorou
{
_contentManager ??= _serviceProvider.GetRequiredService();
var containedAspect = await _contentManager.PopulateAspectAsync(context.PublishingItem);
- await CheckContainedHomeRouteAsync(part.ContentItem.ContentItemId, containedAspect, context.PublishingItem.Content);
+ await CheckContainedHomeRouteAsync(part.ContentItem.ContentItemId, containedAspect, (JsonObject)context.PublishingItem.Content);
}
// Update entries from the index table after the session is committed.
@@ -193,13 +194,13 @@ private Task RemoveTagAsync(AutoroutePart part)
return _tagCache.RemoveTagAsync($"slug:{part.Path}");
}
- private async Task CheckContainedHomeRouteAsync(string containerContentItemId, ContainedContentItemsAspect containedAspect, JObject content)
+ private async Task CheckContainedHomeRouteAsync(string containerContentItemId, ContainedContentItemsAspect containedAspect, JsonObject content)
{
foreach (var accessor in containedAspect.Accessors)
{
var jItems = accessor.Invoke(content);
- foreach (var jItem in jItems.Cast())
+ foreach (var jItem in jItems.Cast())
{
var contentItem = jItem.ToObject();
var handlerAspect = await _contentManager.PopulateAspectAsync(contentItem);
@@ -213,7 +214,7 @@ private async Task CheckContainedHomeRouteAsync(string containerContentItemId, C
await SetHomeRouteAsync(autoroutePart, homeRoute =>
{
homeRoute[_options.ContentItemIdKey] = containerContentItemId;
- homeRoute[_options.JsonPathKey] = jItem.Path;
+ homeRoute[_options.JsonPathKey] = jItem.GetNormalizedPath();
});
break;
@@ -236,18 +237,18 @@ private async Task GenerateContainedPathsFromPatternAsync(ContentItem contentIte
// Build the entries for this content item to evaluate for duplicates.
var entries = new List();
- await PopulateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, contentItem.Content, part.Path);
+ await PopulateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, (JsonObject)contentItem.Content, part.Path);
- await ValidateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, contentItem.Content, part.Path);
+ await ValidateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, (JsonObject)contentItem.Content, part.Path);
}
- private async Task PopulateContainedContentItemRoutesAsync(List entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath)
+ private async Task PopulateContainedContentItemRoutesAsync(List entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JsonObject content, string basePath)
{
foreach (var accessor in containedContentItemsAspect.Accessors)
{
var jItems = accessor.Invoke(content);
- foreach (var jItem in jItems.Cast())
+ foreach (var jItem in jItems.Cast())
{
var contentItem = jItem.ToObject();
var handlerAspect = await _contentManager.PopulateAspectAsync(contentItem);
@@ -260,7 +261,7 @@ private async Task PopulateContainedContentItemRoutesAsync(List
path = (basePath.EndsWith('/') ? basePath : basePath + '/') + handlerAspect.Path.TrimStart('/');
}
- entries.Add(new AutorouteEntry(containerContentItemId, path, contentItem.ContentItemId, jItem.Path)
+ entries.Add(new AutorouteEntry(containerContentItemId, path, contentItem.ContentItemId, jItem.GetNormalizedPath())
{
DocumentId = contentItem.Id
});
@@ -273,13 +274,13 @@ private async Task PopulateContainedContentItemRoutesAsync(List
}
}
- private async Task ValidateContainedContentItemRoutesAsync(List entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath)
+ private async Task ValidateContainedContentItemRoutesAsync(List entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JsonObject content, string basePath)
{
foreach (var accessor in containedContentItemsAspect.Accessors)
{
var jItems = accessor.Invoke(content);
- foreach (var jItem in jItems.Cast())
+ foreach (var jItem in jItems.Cast())
{
var contentItem = jItem.ToObject();
var containedAutoroutePart = contentItem.As();
@@ -297,7 +298,7 @@ private async Task ValidateContainedContentItemRoutesAsync(List
containedAutoroutePart.Apply();
// Merge because we have disconnected the content item from it's json owner.
- jItem.Merge(contentItem.Content, new JsonMergeSettings
+ jItem.Merge((JsonObject)contentItem.Content, new JsonMergeSettings
{
MergeArrayHandling = MergeArrayHandling.Replace,
MergeNullValueHandling = MergeNullValueHandling.Merge
@@ -315,7 +316,7 @@ private async Task ValidateContainedContentItemRoutesAsync(List
containedAutoroutePart.Apply();
// Merge because we have disconnected the content item from it's json owner.
- jItem.Merge(contentItem.Content, new JsonMergeSettings
+ jItem.Merge((JsonObject)contentItem.Content, new JsonMergeSettings
{
MergeArrayHandling = MergeArrayHandling.Replace,
MergeNullValueHandling = MergeNullValueHandling.Merge
diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs
index 143688b62ba..cd8c62e25c0 100644
--- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs
+++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs
@@ -1,5 +1,5 @@
using System.Collections.Generic;
-using Newtonsoft.Json.Linq;
+using System.Text.Json.Nodes;
namespace OrchardCore.ContentManagement.Metadata.Models;
@@ -13,8 +13,8 @@ public static TField GetContentField(
ContentItem contentItem)
where TField : ContentField
{
- if (((JObject)contentItem.Content)[fieldDefinition.PartDefinition.Name] is not JObject jPart ||
- jPart[fieldDefinition.Name] is not JObject jField)
+ if (((JsonObject)contentItem.Content)[fieldDefinition.PartDefinition.Name] is not JsonObject jPart ||
+ jPart[fieldDefinition.Name] is not JsonObject jField)
{
return null;
}
diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/UserNamesExtensions.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/UserNamesExtensions.cs
index 1a10037110f..0fd79733ff6 100644
--- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/UserNamesExtensions.cs
+++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/UserNamesExtensions.cs
@@ -1,5 +1,5 @@
using System;
-using Newtonsoft.Json.Linq;
+using System.Text.Json.Nodes;
namespace OrchardCore.ContentFields.Fields
{
@@ -13,9 +13,9 @@ public static class UserNamesExtensions
///
public static string[] GetUserNames(this UserPickerField userPickerField)
{
- var userNames = userPickerField.Content["UserNames"] as JArray;
+ var userNames = (JsonArray)userPickerField.Content["UserNames"];
- return userNames != null ? userNames.ToObject() : [];
+ return userNames is not null ? userNames.ToObject() : [];
}
///
diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs
index 410dc161988..6e3238a6e04 100644
--- a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs
+++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using GraphQL.Resolvers;
using GraphQL.Types;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentFields.Fields;
using OrchardCore.ContentFields.GraphQL.Types;
using OrchardCore.ContentManagement;
@@ -22,7 +21,7 @@ public class ContentFieldsProvider : IContentFieldProvider
Description = "Boolean field",
FieldType = typeof(BooleanGraphType),
UnderlyingType = typeof(BooleanField),
- FieldAccessor = field => (bool)field.Content.Value
+ FieldAccessor = field => field.Content.Value,
}
},
{
@@ -32,7 +31,7 @@ public class ContentFieldsProvider : IContentFieldProvider
Description = "Date field",
FieldType = typeof(DateGraphType),
UnderlyingType = typeof(DateField),
- FieldAccessor = field => (DateTime?)field.Content.Value
+ FieldAccessor = field => field.Content.Value,
}
},
{
@@ -42,7 +41,7 @@ public class ContentFieldsProvider : IContentFieldProvider
Description = "Date & time field",
FieldType = typeof(DateTimeGraphType),
UnderlyingType = typeof(DateTimeField),
- FieldAccessor = field => (DateTime?)field.Content.Value
+ FieldAccessor = field => field.Content.Value,
}
},
{
@@ -52,7 +51,7 @@ public class ContentFieldsProvider : IContentFieldProvider
Description = "Numeric field",
FieldType = typeof(DecimalGraphType),
UnderlyingType = typeof(NumericField),
- FieldAccessor = field => (decimal?)field.Content.Value
+ FieldAccessor = field => field.Content.Value,
}
},
{
@@ -62,7 +61,7 @@ public class ContentFieldsProvider : IContentFieldProvider
Description = "Text field",
FieldType = typeof(StringGraphType),
UnderlyingType = typeof(TextField),
- FieldAccessor = field => (string)field.Content.Text
+ FieldAccessor = field => field.Content.Text,
}
},
{
@@ -72,7 +71,7 @@ public class ContentFieldsProvider : IContentFieldProvider
Description = "Time field",
FieldType = typeof(TimeSpanGraphType),
UnderlyingType = typeof(TimeField),
- FieldAccessor = field => (TimeSpan?)field.Content.Value
+ FieldAccessor = field => field.Content.Value,
}
},
{
@@ -82,7 +81,7 @@ public class ContentFieldsProvider : IContentFieldProvider
Description = "Multi text field",
FieldType = typeof(ListGraphType),
UnderlyingType = typeof(MultiTextField),
- FieldAccessor = field => ((JArray)field.Content.Values)?.ToObject()
+ FieldAccessor = field => field.Content.Values,
}
}
};
diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs
index 53684debeb6..22c1674d6b3 100644
--- a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs
+++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs
@@ -1,13 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Encodings.Web;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Fluid.Values;
using GraphQL;
using GraphQL.Types;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
-using Newtonsoft.Json.Linq;
using OrchardCore.Apis.GraphQL;
using OrchardCore.ContentFields.Fields;
using OrchardCore.ContentFields.Settings;
@@ -39,9 +39,9 @@ private static async Task
-
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/_ViewImports.cshtml b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/_ViewImports.cshtml
index 4efaff205c4..136e3ff877e 100644
--- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/_ViewImports.cshtml
+++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/_ViewImports.cshtml
@@ -2,10 +2,10 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, OrchardCore.DisplayManagement
@addTagHelper *, OrchardCore.ResourceManagement
+@using System.Text.Json
+@using System.Text.Json.Nodes
@using Microsoft.Extensions.Localization
@using Microsoft.AspNetCore.Mvc.Localization
-@using Newtonsoft.Json
-@using Newtonsoft.Json.Linq
@using OrchardCore.Mvc.Utilities
@using OrchardCore.DisplayManagement
@using OrchardCore.DisplayManagement.Views
diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs
index a58606d9391..8abf5f30e26 100644
--- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs
@@ -1,6 +1,5 @@
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
using OrchardCore.Deployment;
using OrchardCore.Sitemaps.Services;
@@ -8,11 +7,6 @@ namespace OrchardCore.Sitemaps.Deployment
{
public class AllSitemapsDeploymentSource : IDeploymentSource
{
- private static readonly JsonSerializer _serializer = new()
- {
- TypeNameHandling = TypeNameHandling.Auto,
- };
-
private readonly ISitemapManager _sitemapManager;
public AllSitemapsDeploymentSource(ISitemapManager sitemapManager)
@@ -29,12 +23,13 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan
var sitemaps = await _sitemapManager.GetSitemapsAsync();
- var jArray = JArray.FromObject(sitemaps, _serializer);
+ var jArray = JArray.FromObject(sitemaps);
- result.Steps.Add(new JObject(
- new JProperty("name", "Sitemaps"),
- new JProperty("data", jArray)
- ));
+ result.Steps.Add(new JsonObject
+ {
+ ["name"] = "Sitemaps",
+ ["data"] = jArray,
+ });
}
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs
index 86774f544fa..edfc620e226 100644
--- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs
@@ -1,8 +1,7 @@
using System;
using System.Linq;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
using OrchardCore.Sitemaps.Models;
@@ -15,11 +14,6 @@ namespace OrchardCore.Sitemaps.Recipes
///
public class SitemapsStep : IRecipeStepHandler
{
- private static readonly JsonSerializer _serializer = new()
- {
- TypeNameHandling = TypeNameHandling.Auto
- };
-
private readonly ISitemapManager _sitemapManager;
public SitemapsStep(ISitemapManager sitemapManager)
@@ -36,16 +30,16 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
var model = context.Step.ToObject
();
- foreach (var token in model.Data.Cast())
+ foreach (var token in model.Data.Cast())
{
- var sitemap = token.ToObject(_serializer);
+ var sitemap = token.ToObject();
await _sitemapManager.UpdateSitemapAsync(sitemap);
}
}
public class SitemapStepModel
{
- public JArray Data { get; set; }
+ public JsonArray Data { get; set; }
}
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Startup.cs
index 5fb0753847e..e61bc838b53 100644
--- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Startup.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Startup.cs
@@ -1,4 +1,5 @@
using System;
+using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
@@ -91,6 +92,10 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped>();
services.AddRecipeExecutionStep();
+
+ // Allows to serialize 'SitemapType' derived types.
+ services.AddJsonDerivedTypeInfo();
+ services.AddJsonDerivedTypeInfo();
}
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
diff --git a/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs
index 49f813f1d2b..d33fcdce8c1 100644
--- a/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs
@@ -1,3 +1,4 @@
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.ContentTypes.Editors;
@@ -11,7 +12,13 @@ public class GeoPointFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriv
{
public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
{
- return Initialize("GeoPointFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model))
+ return Initialize("GeoPointFieldSettings_Edit", model =>
+ {
+ var settings = partFieldDefinition.Settings.ToObject();
+
+ model.Hint = settings.Hint;
+ model.Required = settings.Required;
+ })
.Location("Content");
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField-Leaflet.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField-Leaflet.Edit.cshtml
index 492ee629e27..78f7e52cd21 100644
--- a/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField-Leaflet.Edit.cshtml
+++ b/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField-Leaflet.Edit.cshtml
@@ -1,6 +1,7 @@
-@using OrchardCore.Spatial.ViewModels
-@using OrchardCore.Spatial.Settings
@using System.Globalization
+@using System.Text.Json.Nodes
+@using OrchardCore.Spatial.Settings
+@using OrchardCore.Spatial.ViewModels
@model EditGeoPointFieldViewModel
@{
var settings = Model.PartFieldDefinition.Settings.ToObject();
diff --git a/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField.Edit.cshtml
index b254f4e64c0..e28bbe4344d 100644
--- a/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField.Edit.cshtml
+++ b/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField.Edit.cshtml
@@ -1,8 +1,9 @@
+@using System.Text.Json.Nodes
+@using OrchardCore
@using OrchardCore.ContentManagement.Metadata.Models
-@using OrchardCore.Spatial.ViewModels
-@using OrchardCore.Spatial.Settings
@using OrchardCore.Mvc.Utilities
-@using OrchardCore
+@using OrchardCore.Spatial.Settings
+@using OrchardCore.Spatial.ViewModels
@model EditGeoPointFieldViewModel
@{
var settings = Model.PartFieldDefinition.Settings.ToObject();
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs
index 85302937baa..34234213ea8 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs
@@ -1,9 +1,10 @@
using System.Linq;
+using System.Text.Json.Nodes;
+using System.Text.Json.Settings;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Localization;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display;
using OrchardCore.ContentManagement.Metadata;
@@ -134,7 +135,7 @@ public async Task CreatePost(string id, string taxonomyContentIte
else
{
// Look for the target taxonomy item in the hierarchy.
- var parentTaxonomyItem = FindTaxonomyItem(taxonomy.As().Content, taxonomyItemId);
+ var parentTaxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId);
// Couldn't find targeted taxonomy item.
if (parentTaxonomyItem == null)
@@ -142,7 +143,7 @@ public async Task CreatePost(string id, string taxonomyContentIte
return NotFound();
}
- var taxonomyItems = parentTaxonomyItem?.Terms as JArray;
+ var taxonomyItems = (JsonArray)parentTaxonomyItem?["Terms"];
if (taxonomyItems == null)
{
@@ -177,7 +178,7 @@ public async Task Edit(string taxonomyContentItemId, string taxon
}
// Look for the target taxonomy item in the hierarchy.
- JObject taxonomyItem = FindTaxonomyItem(taxonomy.As().Content, taxonomyItemId);
+ JsonObject taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId);
// Couldn't find targeted taxonomy item.
if (taxonomyItem == null)
@@ -230,7 +231,7 @@ public async Task EditPost(string taxonomyContentItemId, string t
}
// Look for the target taxonomy item in the hierarchy.
- JObject taxonomyItem = FindTaxonomyItem(taxonomy.As().Content, taxonomyItemId);
+ JsonObject taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId);
// Couldn't find targeted taxonomy item.
if (taxonomyItem == null)
@@ -258,7 +259,7 @@ public async Task EditPost(string taxonomyContentItemId, string t
return View(model);
}
- taxonomyItem.Merge(contentItem.Content, new JsonMergeSettings
+ taxonomyItem.Merge((JsonObject)contentItem.Content, new JsonMergeSettings
{
MergeArrayHandling = MergeArrayHandling.Replace,
MergeNullValueHandling = MergeNullValueHandling.Merge
@@ -304,7 +305,7 @@ public async Task Delete(string taxonomyContentItemId, string tax
}
// Look for the target taxonomy item in the hierarchy.
- var taxonomyItem = FindTaxonomyItem(taxonomy.As().Content, taxonomyItemId);
+ var taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId);
// Couldn't find targeted taxonomy item.
if (taxonomyItem == null)
@@ -312,7 +313,8 @@ public async Task Delete(string taxonomyContentItemId, string tax
return NotFound();
}
- taxonomyItem.Remove();
+ taxonomy.As().Content.Remove(taxonomyItemId);
+
await _session.SaveAsync(taxonomy);
await _notifier.SuccessAsync(H["Taxonomy item deleted successfully."]);
@@ -320,23 +322,20 @@ public async Task Delete(string taxonomyContentItemId, string tax
return RedirectToAction(nameof(Edit), "Admin", new { area = "OrchardCore.Contents", contentItemId = taxonomyContentItemId });
}
- private JObject FindTaxonomyItem(JObject contentItem, string taxonomyItemId)
+ private static JsonObject FindTaxonomyItem(JsonObject contentItem, string taxonomyItemId)
{
if (contentItem["ContentItemId"]?.Value() == taxonomyItemId)
{
return contentItem;
}
- if (contentItem.GetValue("Terms") == null)
+ if (!contentItem.TryGetPropertyValue("Terms", out var terms) || terms is not JsonArray taxonomyItems)
{
return null;
}
- var taxonomyItems = (JArray)contentItem["Terms"];
-
- JObject result;
-
- foreach (var taxonomyItem in taxonomyItems.Cast())
+ JsonObject result;
+ foreach (var taxonomyItem in taxonomyItems.Cast())
{
// Search in inner taxonomy items.
result = FindTaxonomyItem(taxonomyItem, taxonomyItemId);
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs
index 8a1cd945e41..a598ea8e370 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs
@@ -110,4 +110,3 @@ public async Task CreatePost(string taxonomyContentItemId, string
}
}
}
-
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs
index 321f14feb79..865ea3d37a4 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Cysharp.Text;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Localization;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.Contents.ViewModels;
@@ -138,7 +138,7 @@ private static void PopulateTermEntries(List termEntries, IEnum
{
var children = Array.Empty();
- if (contentItem.Content.Terms is JArray termsArray)
+ if (((JsonObject)contentItem.Content)["Terms"] is JsonArray termsArray)
{
children = termsArray.ToObject();
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs
index 936d363ae55..0654ec92aa9 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs
index 79a4177d726..566be2ef874 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using Newtonsoft.Json.Linq;
+using System.Text.Json.Nodes;
using OrchardCore.ContentManagement;
using OrchardCore.Taxonomies.Fields;
using OrchardCore.Taxonomies.ViewModels;
@@ -20,7 +20,7 @@ public static void PopulateTermEntries(List termEntries, TaxonomyFiel
{
var children = Array.Empty();
- if (contentItem.Content.Terms is JArray termsArray)
+ if (((JsonObject)contentItem.Content)["Terms"] is JsonArray termsArray)
{
children = termsArray.ToObject();
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs
index 690b25b1ee3..cefbac24312 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs
@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.Json;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using Newtonsoft.Json.Serialization;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.Models;
@@ -21,11 +20,6 @@ namespace OrchardCore.Taxonomies.Drivers
{
public class TaxonomyFieldTagsDisplayDriver : ContentFieldDisplayDriver
{
- private static readonly JsonSerializerSettings _serializerSettings = new()
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver(),
- };
-
private readonly IContentManager _contentManager;
protected readonly IStringLocalizer S;
@@ -68,7 +62,7 @@ public override IDisplayResult Edit(TaxonomyField field, BuildFieldEditorContext
IsLeaf = te.IsLeaf
});
- model.TagTermEntries = JsonConvert.SerializeObject(tagTermEntries, _serializerSettings);
+ model.TagTermEntries = JNode.FromObject(tagTermEntries, JOptions.CamelCase).ToJsonString(JOptions.Default);
}
model.Field = field;
@@ -109,7 +103,10 @@ public override async Task UpdateAsync(TaxonomyField field, IUpd
foreach (var termContentItemId in field.TermContentItemIds)
{
- var term = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId);
+ var term = TaxonomyOrchardHelperExtensions.FindTerm(
+ (JsonArray)taxonomy.Content["TaxonomyPart"]["Terms"],
+ termContentItemId);
+
terms.Add(term);
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs
index 2a973df24ae..ad02dc12e23 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.Models;
@@ -60,13 +59,13 @@ public override async Task UpdateAsync(TaxonomyPart part, IUpdat
{
var originalTaxonomyItems = part.ContentItem.As();
- var newHierarchy = JArray.Parse(model.Hierarchy);
+ var newHierarchy = JsonNode.Parse(model.Hierarchy).AsArray();
- var taxonomyItems = new JArray();
+ var taxonomyItems = new JsonArray();
foreach (var item in newHierarchy)
{
- taxonomyItems.Add(ProcessItem(originalTaxonomyItems, item as JObject));
+ taxonomyItems.Add(ProcessItem(originalTaxonomyItems, item as JsonObject));
}
part.Terms = taxonomyItems.ToObject>();
@@ -81,7 +80,7 @@ public override async Task UpdateAsync(TaxonomyPart part, IUpdat
///
/// Clone the content items at the specific index.
///
- private static JObject GetTaxonomyItemAt(List taxonomyItems, int[] indexes)
+ private static JsonObject GetTaxonomyItemAt(List taxonomyItems, int[] indexes)
{
ContentItem taxonomyItem = null;
@@ -90,39 +89,39 @@ private static JObject GetTaxonomyItemAt(List taxonomyItems, int[]
{
if (taxonomyItems == null || taxonomyItems.Count < index)
{
- // Trying to acces an unknown index
+ // Trying to access an unknown index
return null;
}
taxonomyItem = taxonomyItems[index];
- var terms = taxonomyItem.Content.Terms as JArray;
+ var terms = (JsonArray)taxonomyItem.Content["Terms"];
taxonomyItems = terms?.ToObject>();
}
- var newObj = JObject.Parse(JsonConvert.SerializeObject(taxonomyItem));
+ var newObj = JObject.FromObject(taxonomyItem);
if (newObj["Terms"] != null)
{
- newObj["Terms"] = new JArray();
+ newObj["Terms"] = new JsonArray();
}
return newObj;
}
- private JObject ProcessItem(TaxonomyPart originalItems, JObject item)
+ private JsonObject ProcessItem(TaxonomyPart originalItems, JsonObject item)
{
var contentItem = GetTaxonomyItemAt(originalItems.Terms, item["index"].ToString().Split('-').Select(x => Convert.ToInt32(x)).ToArray());
- var children = item["children"] as JArray;
+ var children = item["children"] as JsonArray;
- if (children != null)
+ if (children is not null)
{
- var taxonomyItems = new JArray();
+ var taxonomyItems = new JsonArray();
for (var i = 0; i < children.Count; i++)
{
- taxonomyItems.Add(ProcessItem(originalItems, children[i] as JObject));
+ taxonomyItems.Add(ProcessItem(originalItems, children[i] as JsonObject));
contentItem["Terms"] = taxonomyItems;
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Fields/TagNamesExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Fields/TagNamesExtensions.cs
index 01fda5f5182..1d7cad4e3d5 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Fields/TagNamesExtensions.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Fields/TagNamesExtensions.cs
@@ -1,5 +1,5 @@
using System;
-using Newtonsoft.Json.Linq;
+using System.Text.Json.Nodes;
namespace OrchardCore.Taxonomies.Fields
{
@@ -11,7 +11,7 @@ public static class TagNamesExtensions
///
public static string[] GetTagNames(this TaxonomyField taxonomyField)
{
- var tagNames = taxonomyField.Content["TagNames"] as JArray;
+ var tagNames = (JsonArray)taxonomyField.Content["TagNames"];
return tagNames != null ? tagNames.ToObject() : [];
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs
index a25d2c08110..8c55b7b8eac 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
+using System.Text.Json.Nodes;
using GraphQL.Types;
using Microsoft.Extensions.DependencyInjection;
-using Newtonsoft.Json.Linq;
using OrchardCore.Apis.GraphQL;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.GraphQL.Queries.Types;
@@ -52,7 +52,10 @@ public TaxonomyFieldQueryObjectType()
foreach (var termContentItemId in ids)
{
- var term = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId);
+ var term = TaxonomyOrchardHelperExtensions.FindTerm(
+ (JsonArray)taxonomy.Content["TaxonomyPart"]["Terms"],
+ termContentItemId);
+
terms.Add(term);
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TaxonomyPartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TaxonomyPartHandler.cs
index d720fd0fd02..58fd760402c 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TaxonomyPartHandler.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TaxonomyPartHandler.cs
@@ -1,5 +1,5 @@
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.ContentManagement.Routing;
using OrchardCore.Taxonomies.Models;
@@ -12,9 +12,9 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
{
return context.ForAsync(aspect =>
{
- aspect.Accessors.Add((jObject) =>
+ aspect.Accessors.Add((jsonObject) =>
{
- return jObject["TaxonomyPart"]["Terms"] as JArray;
+ return jsonObject["TaxonomyPart"]["Terms"] as JsonArray;
});
return Task.CompletedTask;
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TermPartContentHandler.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TermPartContentHandler.cs
index 6ed2f368e4a..2fde41a6d46 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TermPartContentHandler.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TermPartContentHandler.cs
@@ -1,5 +1,5 @@
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.ContentManagement.Routing;
@@ -12,11 +12,11 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context)
return context.ForAsync(aspect =>
{
// Check this content item contains Terms.
- if (context.ContentItem.Content.Terms is JArray children)
+ if (((JsonNode)context.ContentItem.Content)["Terms"] is JsonArray)
{
- aspect.Accessors.Add((jObject) =>
+ aspect.Accessors.Add((jsonObject) =>
{
- return jObject["Terms"] as JArray;
+ return jsonObject["Terms"] as JsonArray;
});
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs
index 7b4906a088e..a533078fa5e 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
-using Newtonsoft.Json.Linq;
using OrchardCore;
using OrchardCore.ContentManagement;
using OrchardCore.Taxonomies.Indexing;
@@ -30,7 +30,7 @@ public static async Task GetTaxonomyTermAsync(this IOrchardHelper o
return null;
}
- return FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId);
+ return FindTerm((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId);
}
///
@@ -52,7 +52,7 @@ public static async Task> GetInheritedTermsAsync(this IOrchard
var terms = new List();
- FindTermHierarchy(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId, terms);
+ FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId, terms);
return terms;
}
@@ -70,18 +70,18 @@ public static async Task> QueryCategorizedContentItemsA
return await contentManager.LoadAsync(contentItems);
}
- internal static ContentItem FindTerm(JArray termsArray, string termContentItemId)
+ internal static ContentItem FindTerm(JsonArray termsArray, string termContentItemId)
{
- foreach (var term in termsArray.Cast())
+ foreach (var term in termsArray.Cast())
{
- var contentItemId = term.GetValue("ContentItemId").ToString();
+ var contentItemId = term["ContentItemId"]?.ToString();
if (contentItemId == termContentItemId)
{
return term.ToObject();
}
- if (term.GetValue("Terms") is JArray children)
+ if (term["Terms"] is JsonArray children)
{
var found = FindTerm(children, termContentItemId);
@@ -95,11 +95,11 @@ internal static ContentItem FindTerm(JArray termsArray, string termContentItemId
return null;
}
- internal static bool FindTermHierarchy(JArray termsArray, string termContentItemId, List terms)
+ internal static bool FindTermHierarchy(JsonArray termsArray, string termContentItemId, List terms)
{
- foreach (var term in termsArray.Cast())
+ foreach (var term in termsArray.Cast())
{
- var contentItemId = term.GetValue("ContentItemId").ToString();
+ var contentItemId = term["ContentItemId"]?.ToString();
if (contentItemId == termContentItemId)
{
@@ -108,7 +108,7 @@ internal static bool FindTermHierarchy(JArray termsArray, string termContentItem
return true;
}
- if (term.GetValue("Terms") is JArray children)
+ if (term["Terms"] is JsonArray children)
{
var found = FindTermHierarchy(children, termContentItemId, terms);
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs
index 7ef98590fe5..cb0882fbded 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.Contents.Indexing;
using OrchardCore.Indexing;
@@ -42,7 +42,7 @@ public override async Task BuildIndexAsync(TaxonomyField field, BuildFieldIndexC
var inheritedContentItems = new List();
foreach (var contentItemId in field.TermContentItemIds)
{
- TaxonomyOrchardHelperExtensions.FindTermHierarchy(taxonomy.Content.TaxonomyPart.Terms as JArray, contentItemId, inheritedContentItems);
+ TaxonomyOrchardHelperExtensions.FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, contentItemId, inheritedContentItems);
}
foreach (var key in context.Keys)
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs
index 82ca28726d2..a0500909d4e 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text.Json.Nodes;
using Microsoft.Extensions.DependencyInjection;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.Data;
@@ -80,21 +80,19 @@ public override void Describe(DescribeContext context)
// Get all field values
foreach (var fieldDefinition in fieldDefinitions)
{
- var jPart = (JObject)contentItem.Content[fieldDefinition.PartDefinition.Name];
-
- if (jPart == null)
+ var jPart = contentItem.Content[fieldDefinition.PartDefinition.Name];
+ if (jPart is null)
{
continue;
}
- var jField = jPart[fieldDefinition.Name] as JObject;
-
- if (jField == null)
+ var jField = jPart[fieldDefinition.Name];
+ if (jField is null)
{
continue;
}
- var field = jField.ToObject();
+ var field = ((JsonObject)jField).ToObject();
foreach (var termContentItemId in field.TermContentItemIds)
{
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs
index 819494a2dd8..7bb674db146 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs
@@ -1,8 +1,8 @@
using System.Collections.Generic;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Fluid;
using Fluid.Values;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.Liquid;
@@ -36,7 +36,7 @@ public async ValueTask ProcessAsync(FluidValue input, FilterArgument
var terms = new List();
- TaxonomyOrchardHelperExtensions.FindTermHierarchy(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId, terms);
+ TaxonomyOrchardHelperExtensions.FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId, terms);
return FluidValue.Create(terms, ctx.Options);
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs
index 336ee98010c..ad2f392701a 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Fluid;
using Fluid.Values;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.Liquid;
using OrchardCore.Taxonomies.Fields;
@@ -30,12 +30,12 @@ public async ValueTask ProcessAsync(FluidValue input, FilterArgument
termContentItemIds = field.TermContentItemIds;
}
else if (input.Type == FluidValues.Object
- && input.ToObjectValue() is JObject jobj
+ && input.ToObjectValue() is JsonObject jobj
&& jobj.ContainsKey(nameof(TaxonomyField.TermContentItemIds))
&& jobj.ContainsKey(nameof(TaxonomyField.TaxonomyContentItemId)))
{
taxonomyContentItemId = jobj["TaxonomyContentItemId"].Value();
- termContentItemIds = ((JArray)jobj["TermContentItemIds"]).Values().ToArray();
+ termContentItemIds = jobj["TermContentItemIds"].Values().ToArray();
}
else if (input.Type == FluidValues.Array)
{
@@ -58,9 +58,11 @@ public async ValueTask ProcessAsync(FluidValue input, FilterArgument
foreach (var termContentItemId in termContentItemIds)
{
- var term = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId);
+ var term = TaxonomyOrchardHelperExtensions.FindTerm(
+ (JsonArray)taxonomy.Content["TaxonomyPart"]["Terms"],
+ termContentItemId);
- if (term != null)
+ if (term is not null)
{
terms.Add(term);
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs
index adceb7b6935..e70cc65b180 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs
@@ -1,3 +1,4 @@
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.ContentTypes.Editors;
@@ -10,7 +11,17 @@ public class TaxonomyFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriv
{
public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
{
- return Initialize("TaxonomyFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model))
+ return Initialize("TaxonomyFieldSettings_Edit", model =>
+ {
+ var settings = partFieldDefinition.Settings.ToObject();
+
+ model.Hint = settings.Hint;
+ model.Required = settings.Required;
+ model.TaxonomyContentItemId = settings.TaxonomyContentItemId;
+ model.Unique = settings.Unique;
+ model.LeavesOnly = settings.LeavesOnly;
+ model.Open = settings.Open;
+ })
.Location("Content");
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs
index bc0cf6298eb..b40c5972991 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs
@@ -1,3 +1,4 @@
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.ContentTypes.Editors;
@@ -10,8 +11,13 @@ public class TaxonomyFieldTagsEditorSettingsDriver : ContentPartFieldDefinitionD
{
public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
{
- return Initialize("TaxonomyFieldTagsEditorSettings_Edit", model => partFieldDefinition.PopulateSettings(model))
- .Location("Editor");
+ return Initialize("TaxonomyFieldTagsEditorSettings_Edit", model =>
+ {
+ var settings = partFieldDefinition.Settings.ToObject();
+
+ model.Open = settings.Open;
+ })
+ .Location("Content");
}
public override async Task UpdateAsync(ContentPartFieldDefinition partFieldDefinition, UpdatePartFieldEditorContext context)
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs
index 3e10e1bf576..b26847c5947 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
-using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Descriptors;
@@ -89,7 +89,7 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
var termContentItemId = termShape.GetProperty("TermContentItemId");
if (!string.IsNullOrEmpty(termContentItemId))
{
- level = FindTerm(taxonomyContentItem.Content.TaxonomyPart.Terms as JArray, termContentItemId, level, out var termContentItem);
+ level = FindTerm((JsonArray)taxonomyContentItem.Content.TaxonomyPart.Terms, termContentItemId, level, out var termContentItem);
if (termContentItem == null)
{
@@ -133,7 +133,7 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
foreach (var termContentItem in termItems)
{
ContentItem[] childTerms = null;
- if (termContentItem.Content.Terms is JArray termsArray)
+ if (((JsonObject)termContentItem.Content)["Terms"] is JsonArray termsArray)
{
childTerms = termsArray.ToObject();
}
@@ -171,7 +171,7 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
foreach (var termContentItem in termItem.GetProperty("Terms"))
{
ContentItem[] childTerms = null;
- if (termContentItem.Content.Terms is JArray termsArray)
+ if (((JsonObject)termContentItem.Content)["Terms"] is JsonArray termsArray)
{
childTerms = termsArray.ToObject();
}
@@ -250,19 +250,18 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
return ValueTask.CompletedTask;
}
- private static int FindTerm(JArray termsArray, string termContentItemId, int level, out ContentItem contentItem)
+ private int FindTerm(JsonArray termsArray, string termContentItemId, int level, out ContentItem contentItem)
{
- foreach (var term in termsArray.Cast())
+ foreach (var term in termsArray.Cast())
{
- var contentItemId = term.GetValue("ContentItemId").ToString();
-
+ var contentItemId = term["ContentItemId"]?.ToString();
if (contentItemId == termContentItemId)
{
contentItem = term.ToObject();
return level;
}
- if (term.GetValue("Terms") is JArray children)
+ if (term["Terms"] is JsonArray children)
{
level += 1;
level = FindTerm(children, termContentItemId, level, out var foundContentItem);
diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml
index 50604684206..3f7a4ae7e53 100644
--- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml
+++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml
@@ -1,11 +1,11 @@
-@using Newtonsoft.Json.Linq
+@using System.Text.Json.Nodes
@inject OrchardCore.ContentManagement.Display.IContentItemDisplayManager ContentItemDisplayManager
@inject OrchardCore.DisplayManagement.ModelBinding.IUpdateModelAccessor ModelUpdaterAccessor
@{
ContentItem contentItem = Model.ContentItem;
- JArray termsArray = contentItem.Content.Terms;
+ var termsArray = (JsonArray)contentItem.Content.Terms;
var index = 0;
}
@@ -52,7 +52,7 @@
var updater = ModelUpdaterAccessor.ModelUpdater;
*@
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllAdminTemplatesDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllAdminTemplatesDeploymentSource.cs
index c7fd9ee2555..a7c3c0cd5c9 100644
--- a/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllAdminTemplatesDeploymentSource.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllAdminTemplatesDeploymentSource.cs
@@ -1,6 +1,6 @@
using System.Text;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using Newtonsoft.Json.Linq;
using OrchardCore.Deployment;
using OrchardCore.Templates.Models;
using OrchardCore.Templates.Services;
@@ -25,7 +25,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan
return;
}
- var templateObjects = new JObject();
+ var templateObjects = new JsonObject();
var templates = await _templatesManager.GetTemplatesDocumentAsync();
if (allTemplatesStep.ExportAsFiles)
@@ -46,10 +46,11 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan
}
}
- result.Steps.Add(new JObject(
- new JProperty("name", "AdminTemplates"),
- new JProperty("AdminTemplates", templateObjects)
- ));
+ result.Steps.Add(new JsonObject
+ {
+ ["name"] = "AdminTemplates",
+ ["AdminTemplates"] = templateObjects,
+ });
}
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllTemplatesDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllTemplatesDeploymentSource.cs
index d31da146370..83d004cc175 100644
--- a/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllTemplatesDeploymentSource.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllTemplatesDeploymentSource.cs
@@ -1,6 +1,6 @@
using System.Text;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using Newtonsoft.Json.Linq;
using OrchardCore.Deployment;
using OrchardCore.Templates.Models;
using OrchardCore.Templates.Services;
@@ -25,7 +25,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan
return;
}
- var templateObjects = new JObject();
+ var templateObjects = new JsonObject();
var templates = await _templatesManager.GetTemplatesDocumentAsync();
if (allTemplatesStep.ExportAsFiles)
@@ -46,10 +46,11 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan
}
}
- result.Steps.Add(new JObject(
- new JProperty("name", "Templates"),
- new JProperty("Templates", templateObjects)
- ));
+ result.Steps.Add(new JsonObject
+ {
+ ["name"] = "Templates",
+ ["Templates"] = templateObjects,
+ });
}
}
}
diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs
index 492969f3119..21709373b7e 100644
--- a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs
+++ b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs
@@ -1,6 +1,6 @@
using System;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using Newtonsoft.Json.Linq;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
using OrchardCore.Templates.Models;
@@ -27,11 +27,11 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
return;
}
- if (context.Step.Property("AdminTemplates").Value is JObject templates)
+ if (context.Step.TryGetPropertyValue("AdminTemplates", out var jsonNode) && jsonNode is JsonObject templates)
{
- foreach (var property in templates.Properties())
+ foreach (var property in templates)
{
- var name = property.Name;
+ var name = property.Key;
var value = property.Value.ToObject