From b8d7cee576c951e3ce244ca6ad2f2f5199dafd95 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Tue, 13 Feb 2024 17:00:12 -0800 Subject: [PATCH 01/11] Add IJsonSerializer and register JsonSerializerOptions --- .../Deployment/AdminMenuDeploymentSource.cs | 11 +---- .../Recipes/AdminMenuStep.cs | 9 +--- .../ContentDefinitionDeploymentSource.cs | 12 +++-- ...eplaceContentDefinitionDeploymentSource.cs | 12 +++-- .../ContentItemDeploymentSource.cs | 10 +++- .../Deployment/AllContentDeploymentSource.cs | 10 +++- .../Deployment/ContentDeploymentSource.cs | 10 +++- ...ntentToDeploymentTargetDeploymentSource.cs | 11 +++-- .../CustomSettingsDeploymentSource.cs | 10 +++- .../DeploymentPlanDeploymentSource.cs | 9 +++- .../Steps/CustomFileDeploymentSource.cs | 4 +- .../Deployment/AllFeaturesDeploymentSource.cs | 11 +++-- .../Deployment/AllLayersDeploymentSource.cs | 9 +--- .../OrchardCore.Layers/Recipes/LayerStep.cs | 10 +--- .../AllMediaProfilesDeploymentSource.cs | 14 ++++-- .../Deployment/AzureADDeploymentSource.cs | 10 +++- .../OpenIdServerDeploymentSource.cs | 10 +++- .../OpenIdValidationDeploymentSource.cs | 10 +++- .../Deployment/PlacementsDeploymentSource.cs | 14 ++++-- .../Deployment/AllQueriesDeploymentSource.cs | 10 +++- .../QueryBasedContentDeploymentSource.cs | 9 +++- .../AllShortcodeTemplatesDeploymentSource.cs | 10 +++- .../Deployment/AllSitemapsDeploymentSource.cs | 10 +++- .../Deployment/AllUsersDeploymentSource.cs | 10 +++- .../CustomUserSettingsDeploymentSource.cs | 11 ++++- .../AllWorkflowTypeDeploymentSource.cs | 10 +++- .../JsonSerializerOptionsConfiguration.cs | 42 +++++++++++++++++ .../Json/DefaultJsonSerializer.cs | 27 +++++++++++ .../Json/IJsonSerializer.cs | 35 ++++++++++++++ .../DefaultJsonContentSerializer.cs | 47 +++++-------------- .../OrchardCoreBuilderExtensions.cs | 8 +--- .../SiteSettingsPropertyDeploymentSource.cs | 10 +++- .../Extensions/ServiceCollectionExtensions.cs | 6 +++ .../GraphQL/ContentItemsFieldTypeTests.cs | 23 +++++++-- .../OpenIdServerDeploymentSourceTests.cs | 12 ++++- 35 files changed, 344 insertions(+), 132 deletions(-) create mode 100644 src/OrchardCore/OrchardCore.Abstractions/Extensions/JsonSerializerOptionsConfiguration.cs create mode 100644 src/OrchardCore/OrchardCore.Abstractions/Json/DefaultJsonSerializer.cs create mode 100644 src/OrchardCore/OrchardCore.Abstractions/Json/IJsonSerializer.cs diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs index e07ba5551ef..0cb65240c45 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs @@ -1,11 +1,9 @@ using System.Text.Json; using System.Text.Json.Nodes; -using System.Text.Json.Serialization; using System.Threading.Tasks; using Microsoft.Extensions.Options; using OrchardCore.AdminMenu.Services; using OrchardCore.Deployment; -using OrchardCore.Json; namespace OrchardCore.AdminMenu.Deployment { @@ -14,15 +12,10 @@ public class AdminMenuDeploymentSource : IDeploymentSource private readonly IAdminMenuService _adminMenuService; private readonly JsonSerializerOptions _serializationOptions; - public AdminMenuDeploymentSource(IAdminMenuService adminMenuService, IOptions derivedTypesOptions) + public AdminMenuDeploymentSource(IAdminMenuService adminMenuService, IOptions serializationOptions) { _adminMenuService = adminMenuService; - - // The recipe step contains polymorphic types which need to be resolved - _serializationOptions = new() - { - TypeInfoResolver = new PolymorphicJsonTypeInfoResolver(derivedTypesOptions.Value) - }; + _serializationOptions = serializationOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs index 1e578340f61..10ce21a711f 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs @@ -2,11 +2,9 @@ using System.Linq; using System.Text.Json; using System.Text.Json.Nodes; -using System.Text.Json.Serialization; using System.Threading.Tasks; using Microsoft.Extensions.Options; using OrchardCore.AdminMenu.Services; -using OrchardCore.Json; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -20,15 +18,12 @@ public class AdminMenuStep : IRecipeStepHandler private readonly IAdminMenuService _adminMenuService; private readonly JsonSerializerOptions _serializationOptions; - public AdminMenuStep(IAdminMenuService adminMenuService, IOptions derivedTypesOptions) + public AdminMenuStep(IAdminMenuService adminMenuService, IOptions serializationOptions) { _adminMenuService = adminMenuService; // The recipe step contains polymorphic types (menu items) which need to be resolved - _serializationOptions = new() - { - TypeInfoResolver = new PolymorphicJsonTypeInfoResolver(derivedTypesOptions.Value) - }; + _serializationOptions = serializationOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ContentDefinitionDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ContentDefinitionDeploymentSource.cs index 2f88284061e..6d7d4e50708 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ContentDefinitionDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ContentDefinitionDeploymentSource.cs @@ -1,6 +1,8 @@ using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Deployment; @@ -9,10 +11,14 @@ namespace OrchardCore.ContentTypes.Deployment public class ContentDefinitionDeploymentSource : IDeploymentSource { private readonly IContentDefinitionStore _contentDefinitionStore; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ContentDefinitionDeploymentSource(IContentDefinitionStore contentDefinitionStore) + public ContentDefinitionDeploymentSource( + IContentDefinitionStore contentDefinitionStore, + IOptions jsonSerializerOptions) { _contentDefinitionStore = contentDefinitionStore; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -37,8 +43,8 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "ContentDefinition", - ["ContentTypes"] = JArray.FromObject(contentTypes), - ["ContentParts"] = JArray.FromObject(contentParts), + ["ContentTypes"] = JArray.FromObject(contentTypes, _jsonSerializerOptions), + ["ContentParts"] = JArray.FromObject(contentParts, _jsonSerializerOptions), }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ReplaceContentDefinitionDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ReplaceContentDefinitionDeploymentSource.cs index 0b35e8c324d..968ce503df5 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ReplaceContentDefinitionDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ReplaceContentDefinitionDeploymentSource.cs @@ -1,6 +1,8 @@ using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Deployment; @@ -9,10 +11,14 @@ namespace OrchardCore.ContentTypes.Deployment public class ReplaceContentDefinitionDeploymentSource : IDeploymentSource { private readonly IContentDefinitionStore _contentDefinitionStore; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ReplaceContentDefinitionDeploymentSource(IContentDefinitionStore contentDefinitionStore) + public ReplaceContentDefinitionDeploymentSource( + IContentDefinitionStore contentDefinitionStore, + IOptions jsonSerializerOptions) { _contentDefinitionStore = contentDefinitionStore; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -37,8 +43,8 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "ReplaceContentDefinition", - ["ContentTypes"] = JArray.FromObject(contentTypes), - ["ContentParts"] = JArray.FromObject(contentParts), + ["ContentTypes"] = JArray.FromObject(contentTypes, _jsonSerializerOptions), + ["ContentParts"] = JArray.FromObject(contentParts, _jsonSerializerOptions), }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/ContentItemDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/ContentItemDeploymentSource.cs index ab433038e8a..7dbf7d8ecf4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/ContentItemDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/ContentItemDeploymentSource.cs @@ -1,6 +1,8 @@ using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Deployment; @@ -9,10 +11,14 @@ namespace OrchardCore.Contents.Deployment.AddToDeploymentPlan public class ContentItemDeploymentSource : IDeploymentSource { private readonly IContentManager _contentManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ContentItemDeploymentSource(IContentManager contentManager) + public ContentItemDeploymentSource( + IContentManager contentManager, + IOptions jsonSerializerOptions) { _contentManager = contentManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -31,7 +37,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var jContentItem = JObject.FromObject(contentItem); + var jContentItem = JObject.FromObject(contentItem, _jsonSerializerOptions); jContentItem.Remove(nameof(ContentItem.Id)); var contentStep = result.Steps.FirstOrDefault(s => s["name"]?.ToString() == "Content"); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AllContentDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AllContentDeploymentSource.cs index 25c2c8002c1..dd1aa9cfd1e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AllContentDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AllContentDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Records; using OrchardCore.Deployment; @@ -10,10 +12,14 @@ namespace OrchardCore.Contents.Deployment public class AllContentDeploymentSource : IDeploymentSource { private readonly ISession _session; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllContentDeploymentSource(ISession session) + public AllContentDeploymentSource( + ISession session, + IOptions jsonSerializerOptions) { _session = session; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -34,7 +40,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var contentItem in await _session.Query(x => x.Published).ListAsync()) { - var objectData = JObject.FromObject(contentItem); + var objectData = JObject.FromObject(contentItem, _jsonSerializerOptions); // Don't serialize the Id as it could be interpreted as an updated object when added back to YesSql objectData.Remove(nameof(ContentItem.Id)); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ContentDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ContentDeploymentSource.cs index 02cd18cdad5..afcd974f5e4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ContentDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ContentDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Records; using OrchardCore.Deployment; @@ -11,10 +13,14 @@ namespace OrchardCore.Contents.Deployment public class ContentDeploymentSource : IDeploymentSource { private readonly ISession _session; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ContentDeploymentSource(ISession session) + public ContentDeploymentSource( + ISession session, + IOptions jsonSerializerOptions) { _session = session; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -32,7 +38,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var contentItem in await _session.Query(x => x.Published && x.ContentType.IsIn(contentStep.ContentTypes)).ListAsync()) { - var objectData = JObject.FromObject(contentItem); + var objectData = JObject.FromObject(contentItem, _jsonSerializerOptions); // Don't serialize the Id as it could be interpreted as an updated object when added back to YesSql. objectData.Remove(nameof(ContentItem.Id)); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetDeploymentSource.cs index ddc4f0d4748..9e0273d8caf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetDeploymentSource.cs @@ -1,8 +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.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Records; using OrchardCore.Deployment; @@ -17,15 +19,18 @@ public class ExportContentToDeploymentTargetDeploymentSource : IDeploymentSource private readonly IContentManager _contentManager; private readonly ISession _session; private readonly IUpdateModelAccessor _updateModelAccessor; + private readonly JsonSerializerOptions _jsonSerializerOptions; public ExportContentToDeploymentTargetDeploymentSource( IContentManager contentManager, ISession session, - IUpdateModelAccessor updateModelAccessor) + IUpdateModelAccessor updateModelAccessor, + IOptions jsonSerializerOptions) { _contentManager = contentManager; _session = session; _updateModelAccessor = updateModelAccessor; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -52,7 +57,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var contentItem = await _contentManager.GetAsync(model.ContentItemId, model.Latest ? VersionOptions.Latest : VersionOptions.Published); if (contentItem != null) { - var objectData = JObject.FromObject(contentItem); + var objectData = JObject.FromObject(contentItem, _jsonSerializerOptions); objectData.Remove(nameof(ContentItem.Id)); data.Add(objectData); } @@ -64,7 +69,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var contentItem in checkedContentItems) { - var objectData = JObject.FromObject(contentItem); + var objectData = JObject.FromObject(contentItem, _jsonSerializerOptions); objectData.Remove(nameof(ContentItem.Id)); data.Add(objectData); } diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentSource.cs index 73382cf61d8..d91b9b2087c 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Deployment/CustomSettingsDeploymentSource.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.CustomSettings.Services; using OrchardCore.Deployment; @@ -10,10 +12,14 @@ namespace OrchardCore.CustomSettings.Deployment public class CustomSettingsDeploymentSource : IDeploymentSource { private readonly CustomSettingsService _customSettingsService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public CustomSettingsDeploymentSource(CustomSettingsService customSettingsService) + public CustomSettingsDeploymentSource( + CustomSettingsService customSettingsService, + IOptions jsonSerializerOptions) { _customSettingsService = customSettingsService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -44,7 +50,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var settingsType in settingsTypes) { var settings = await _customSettingsService.GetSettingsAsync(settingsType); - settingsList.Add(new(settings.ContentType, JObject.FromObject(settings))); + settingsList.Add(new(settings.ContentType, JObject.FromObject(settings, _jsonSerializerOptions))); } // Adding custom settings diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment/Deployment/DeploymentPlanDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Deployment/Deployment/DeploymentPlanDeploymentSource.cs index f122b92eded..8f3c6f1b867 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment/Deployment/DeploymentPlanDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment/Deployment/DeploymentPlanDeploymentSource.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; namespace OrchardCore.Deployment.Deployment { @@ -9,13 +11,16 @@ public class DeploymentPlanDeploymentSource : IDeploymentSource { private readonly IDeploymentPlanService _deploymentPlanService; private readonly IEnumerable _deploymentStepFactories; + private readonly JsonSerializerOptions _jsonSerializerOptions; public DeploymentPlanDeploymentSource( IDeploymentPlanService deploymentPlanService, - IEnumerable deploymentStepFactories) + IEnumerable deploymentStepFactories, + IOptions jsonSerializerOptions) { _deploymentPlanService = deploymentPlanService; _deploymentStepFactories = deploymentStepFactories; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep deploymentStep, DeploymentPlanResult result) @@ -52,7 +57,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep deploymentStep, Depl result.Steps.Add(new JsonObject { ["name"] = "deployment", - ["Plans"] = JArray.FromObject(plans), + ["Plans"] = JArray.FromObject(plans, _jsonSerializerOptions), }); } diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment/Steps/CustomFileDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Deployment/Steps/CustomFileDeploymentSource.cs index 677ad1323f8..c5586213017 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment/Steps/CustomFileDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment/Steps/CustomFileDeploymentSource.cs @@ -7,9 +7,7 @@ public class CustomFileDeploymentSource : IDeploymentSource { public Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) { - var customFile = step as CustomFileDeploymentStep; - - if (customFile == null) + if (step is not CustomFileDeploymentStep customFile) { return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Features/Deployment/AllFeaturesDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Features/Deployment/AllFeaturesDeploymentSource.cs index 882fceed3fd..577cd9c4217 100644 --- a/src/OrchardCore.Modules/OrchardCore.Features/Deployment/AllFeaturesDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Features/Deployment/AllFeaturesDeploymentSource.cs @@ -1,6 +1,8 @@ using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Features.Services; @@ -9,10 +11,13 @@ namespace OrchardCore.Features.Deployment public class AllFeaturesDeploymentSource : IDeploymentSource { private readonly IModuleService _moduleService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllFeaturesDeploymentSource(IModuleService moduleService) + public AllFeaturesDeploymentSource(IModuleService moduleService, + IOptions jsonSerializerOptions) { _moduleService = moduleService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -28,12 +33,12 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var featureStep = new JsonObject { ["name"] = "Feature", - ["enable"] = JNode.FromObject(features.Where(f => f.IsEnabled).Select(f => f.Descriptor.Id).ToArray()), + ["enable"] = JNode.FromObject(features.Where(f => f.IsEnabled).Select(f => f.Descriptor.Id).ToArray(), _jsonSerializerOptions), }; if (!allFeaturesStep.IgnoreDisabledFeatures) { - featureStep.Add("disable", JNode.FromObject(features.Where(f => !f.IsEnabled).Select(f => f.Descriptor.Id).ToArray())); + featureStep.Add("disable", JNode.FromObject(features.Where(f => !f.IsEnabled).Select(f => f.Descriptor.Id).ToArray(), _jsonSerializerOptions)); } result.Steps.Add(featureStep); diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs index 7b30fe6f5bf..b3ede9b408d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs @@ -1,10 +1,8 @@ using System.Text.Json; using System.Text.Json.Nodes; -using System.Text.Json.Serialization; using System.Threading.Tasks; using Microsoft.Extensions.Options; using OrchardCore.Deployment; -using OrchardCore.Json; using OrchardCore.Layers.Models; using OrchardCore.Layers.Services; using OrchardCore.Settings; @@ -20,16 +18,13 @@ public class AllLayersDeploymentSource : IDeploymentSource public AllLayersDeploymentSource( ILayerService layerService, ISiteService siteService, - IOptions derivedTypesOptions) + IOptions serializationOptions) { _layerService = layerService; _siteService = siteService; // The recipe step contains polymorphic types which need to be resolved - _serializationOptions = new() - { - TypeInfoResolver = new PolymorphicJsonTypeInfoResolver(derivedTypesOptions.Value) - }; + _serializationOptions = serializationOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs index 2c6ba7d64dd..43ec709329e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Recipes/LayerStep.cs @@ -3,10 +3,8 @@ using System.Linq; using System.Text.Json; using System.Text.Json.Nodes; -using System.Text.Json.Serialization; using System.Threading.Tasks; using Microsoft.Extensions.Options; -using OrchardCore.Json; using OrchardCore.Layers.Models; using OrchardCore.Layers.Services; using OrchardCore.Recipes.Models; @@ -32,17 +30,13 @@ public LayerStep( IRuleMigrator ruleMigrator, IConditionIdGenerator conditionIdGenerator, IEnumerable factories, - IOptions derivedTypesOptions) + IOptions serializationOptions) { _layerService = layerService; _ruleMigrator = ruleMigrator; _conditionIdGenerator = conditionIdGenerator; _factories = factories; - - _serializationOptions = new() - { - TypeInfoResolver = new PolymorphicJsonTypeInfoResolver(derivedTypesOptions.Value) - }; + _serializationOptions = serializationOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Deployment/AllMediaProfilesDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Media/Deployment/AllMediaProfilesDeploymentSource.cs index 6c88cdf7683..259b1a7d795 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Deployment/AllMediaProfilesDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Deployment/AllMediaProfilesDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Media.Services; @@ -8,17 +10,19 @@ namespace OrchardCore.Media.Deployment public class AllMediaProfilesDeploymentSource : IDeploymentSource { private readonly MediaProfilesManager _mediaProfilesManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllMediaProfilesDeploymentSource(MediaProfilesManager mediaProfilesManager) + public AllMediaProfilesDeploymentSource( + MediaProfilesManager mediaProfilesManager, + IOptions jsonSerializerOptions) { _mediaProfilesManager = mediaProfilesManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) { - var allMediaProfilesStep = step as AllMediaProfilesDeploymentStep; - - if (allMediaProfilesStep == null) + if (step is not AllMediaProfilesDeploymentStep) { return; } @@ -28,7 +32,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "MediaProfiles", - ["MediaProfiles"] = JObject.FromObject(mediaProfiles.MediaProfiles), + ["MediaProfiles"] = JObject.FromObject(mediaProfiles.MediaProfiles, _jsonSerializerOptions), }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Deployment/AzureADDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Deployment/AzureADDeploymentSource.cs index ce399d0b817..ceba03020ef 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Deployment/AzureADDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Deployment/AzureADDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Microsoft.Authentication.Services; using OrchardCore.Microsoft.Authentication.Settings; @@ -9,10 +11,14 @@ namespace OrchardCore.Microsoft.Authentication.Deployment public class AzureADDeploymentSource : IDeploymentSource { private readonly IAzureADService _azureADService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AzureADDeploymentSource(IAzureADService azureADService) + public AzureADDeploymentSource( + IAzureADService azureADService, + IOptions jsonSerializerOptions) { _azureADService = azureADService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -28,7 +34,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var obj = new JsonObject { ["name"] = nameof(AzureADSettings) }; - obj.Merge(JObject.FromObject(settings)); + obj.Merge(JObject.FromObject(settings, _jsonSerializerOptions)); result.Steps.Add(obj); } diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Deployment/OpenIdServerDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Deployment/OpenIdServerDeploymentSource.cs index a3474788075..460176858ab 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Deployment/OpenIdServerDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Deployment/OpenIdServerDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.OpenId.Recipes; using OrchardCore.OpenId.Services; @@ -10,10 +12,14 @@ namespace OrchardCore.OpenId.Deployment public class OpenIdServerDeploymentSource : IDeploymentSource { private readonly IOpenIdServerService _openIdServerService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public OpenIdServerDeploymentSource(IOpenIdServerService openIdServerService) + public OpenIdServerDeploymentSource( + IOpenIdServerService openIdServerService, + IOptions jsonSerializerOptions) { _openIdServerService = openIdServerService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -70,7 +76,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan ["name"] = nameof(OpenIdServerSettings), }; - obj.Merge(JObject.FromObject(settingsModel)); + obj.Merge(JObject.FromObject(settingsModel, _jsonSerializerOptions)); result.Steps.Add(obj); } diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Deployment/OpenIdValidationDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Deployment/OpenIdValidationDeploymentSource.cs index 66bd3305445..913548cd662 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Deployment/OpenIdValidationDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Deployment/OpenIdValidationDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.OpenId.Services; using OrchardCore.OpenId.Settings; @@ -9,10 +11,14 @@ namespace OrchardCore.OpenId.Deployment public class OpenIdValidationDeploymentSource : IDeploymentSource { private readonly IOpenIdValidationService _openIdValidationService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public OpenIdValidationDeploymentSource(IOpenIdValidationService openIdValidationService) + public OpenIdValidationDeploymentSource( + IOpenIdValidationService openIdValidationService, + IOptions jsonSerializerOptions) { _openIdValidationService = openIdValidationService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -30,7 +36,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var jObject = new JsonObject { ["name"] = nameof(OpenIdValidationSettings) }; // Merge settings as the recipe step doesn't use a child property. - jObject.Merge(JObject.FromObject(validationSettings)); + jObject.Merge(JObject.FromObject(validationSettings, _jsonSerializerOptions)); result.Steps.Add(jObject); } diff --git a/src/OrchardCore.Modules/OrchardCore.Placements/Deployment/PlacementsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Placements/Deployment/PlacementsDeploymentSource.cs index f2c92873ab3..be178f4910b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Placements/Deployment/PlacementsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Placements/Deployment/PlacementsDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Placements.Services; @@ -8,17 +10,19 @@ namespace OrchardCore.Placements.Deployment public class PlacementsDeploymentSource : IDeploymentSource { private readonly PlacementsManager _placementsManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public PlacementsDeploymentSource(PlacementsManager placementsManager) + public PlacementsDeploymentSource( + PlacementsManager placementsManager, + IOptions jsonSerializerOptions) { _placementsManager = placementsManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) { - var placementsStep = step as PlacementsDeploymentStep; - - if (placementsStep == null) + if (step is not PlacementsDeploymentStep) { return; } @@ -28,7 +32,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var placement in placements) { - placementObjects[placement.Key] = JArray.FromObject(placement.Value); + placementObjects[placement.Key] = JArray.FromObject(placement.Value, _jsonSerializerOptions); } result.Steps.Add(new JsonObject diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Deployment/AllQueriesDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Deployment/AllQueriesDeploymentSource.cs index 7c7b4643f07..7ecdc9e65a8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Deployment/AllQueriesDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Deployment/AllQueriesDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; namespace OrchardCore.Queries.Deployment @@ -7,10 +9,14 @@ namespace OrchardCore.Queries.Deployment public class AllQueriesDeploymentSource : IDeploymentSource { private readonly IQueryManager _queryManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllQueriesDeploymentSource(IQueryManager queryManager) + public AllQueriesDeploymentSource( + IQueryManager queryManager, + IOptions jsonSerializerOptions) { _queryManager = queryManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -27,7 +33,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "Queries", - ["Queries"] = JArray.FromObject(queries), + ["Queries"] = JArray.FromObject(queries, _jsonSerializerOptions), }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Deployment/QueryBasedContentDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Deployment/QueryBasedContentDeploymentSource.cs index 7add2e2caaa..65e65765f83 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Deployment/QueryBasedContentDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Deployment/QueryBasedContentDeploymentSource.cs @@ -2,6 +2,7 @@ using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Deployment; @@ -10,10 +11,14 @@ namespace OrchardCore.Queries.Deployment public class QueryBasedContentDeploymentSource : IDeploymentSource { private readonly IQueryManager _queryManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public QueryBasedContentDeploymentSource(IQueryManager queryManager) + public QueryBasedContentDeploymentSource( + IQueryManager queryManager, + IOptions jsonSerializerOptions) { _queryManager = queryManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -48,7 +53,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var contentItem in results.Items) { - var objectData = JObject.FromObject(contentItem); + var objectData = JObject.FromObject(contentItem, _jsonSerializerOptions); // Don't serialize the Id as it could be interpreted as an updated object when added back to YesSql. objectData.Remove(nameof(ContentItem.Id)); diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Deployment/AllShortcodeTemplatesDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Deployment/AllShortcodeTemplatesDeploymentSource.cs index 5c4eaf2d69c..1934fd4b718 100644 --- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Deployment/AllShortcodeTemplatesDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Deployment/AllShortcodeTemplatesDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Shortcodes.Services; @@ -8,10 +10,14 @@ namespace OrchardCore.Shortcodes.Deployment public class AllShortcodeTemplatesDeploymentSource : IDeploymentSource { private readonly ShortcodeTemplatesManager _templatesManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllShortcodeTemplatesDeploymentSource(ShortcodeTemplatesManager templatesManager) + public AllShortcodeTemplatesDeploymentSource( + ShortcodeTemplatesManager templatesManager, + IOptions jsonSerializerOptions) { _templatesManager = templatesManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -28,7 +34,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var template in templates.ShortcodeTemplates) { - templateObjects[template.Key] = JObject.FromObject(template.Value); + templateObjects[template.Key] = JObject.FromObject(template.Value, _jsonSerializerOptions); } result.Steps.Add(new JsonObject diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs index 8abf5f30e26..b027878e50f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Sitemaps.Services; @@ -8,10 +10,14 @@ namespace OrchardCore.Sitemaps.Deployment public class AllSitemapsDeploymentSource : IDeploymentSource { private readonly ISitemapManager _sitemapManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllSitemapsDeploymentSource(ISitemapManager sitemapManager) + public AllSitemapsDeploymentSource( + ISitemapManager sitemapManager, + IOptions jsonSerializerOptions) { _sitemapManager = sitemapManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -23,7 +29,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var sitemaps = await _sitemapManager.GetSitemapsAsync(); - var jArray = JArray.FromObject(sitemaps); + var jArray = JArray.FromObject(sitemaps, _jsonSerializerOptions); result.Steps.Add(new JsonObject { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs index 69d3b418593..cf6e4cc429a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Users.Models; using YesSql; @@ -9,10 +11,14 @@ namespace OrchardCore.Users.Deployment; public class AllUsersDeploymentSource : IDeploymentSource { private readonly ISession _session; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllUsersDeploymentSource(ISession session) + public AllUsersDeploymentSource( + ISession session, + IOptions jsonSerializerOptions) { _session = session; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -47,7 +53,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan IsLockoutEnabled = user.IsLockoutEnabled, AccessFailedCount = user.AccessFailedCount, RoleNames = user.RoleNames, - })); + }, _jsonSerializerOptions)); } result.Steps.Add(new JsonObject diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs index ab00d50ab2e..294bf6b8a93 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs @@ -1,6 +1,8 @@ using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Users.Models; using OrchardCore.Users.Services; @@ -12,11 +14,16 @@ public class CustomUserSettingsDeploymentSource : IDeploymentSource { private readonly CustomUserSettingsService _customUserSettingsService; private readonly ISession _session; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public CustomUserSettingsDeploymentSource(CustomUserSettingsService customUserSettingsService, ISession session) + public CustomUserSettingsDeploymentSource( + CustomUserSettingsService customUserSettingsService, + ISession session, + IOptions jsonSerializerOptions) { _customUserSettingsService = customUserSettingsService; _session = session; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -41,7 +48,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var settingsType in settingsTypes) { var userSetting = await _customUserSettingsService.GetSettingsAsync(user, settingsType); - userSettingsData.Add(JObject.FromObject(userSetting)); + userSettingsData.Add(JObject.FromObject(userSetting, _jsonSerializerOptions)); } userData.Add(new JsonObject diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Deployment/AllWorkflowTypeDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Deployment/AllWorkflowTypeDeploymentSource.cs index 40e1bf881a5..521d75c524c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Deployment/AllWorkflowTypeDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Deployment/AllWorkflowTypeDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Workflows.Services; @@ -8,10 +10,14 @@ namespace OrchardCore.Workflows.Deployment public class AllWorkflowTypeDeploymentSource : IDeploymentSource { private readonly IWorkflowTypeStore _workflowTypeStore; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllWorkflowTypeDeploymentSource(IWorkflowTypeStore workflowTypeStore) + public AllWorkflowTypeDeploymentSource( + IWorkflowTypeStore workflowTypeStore, + IOptions jsonSerializerOptions) { _workflowTypeStore = workflowTypeStore; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -32,7 +38,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var workflow in await _workflowTypeStore.ListAsync()) { - var objectData = JObject.FromObject(workflow); + var objectData = JObject.FromObject(workflow, _jsonSerializerOptions); // Don't serialize the Id as it could be interpreted as an updated object when added back to YesSql objectData.Remove(nameof(workflow.Id)); diff --git a/src/OrchardCore/OrchardCore.Abstractions/Extensions/JsonSerializerOptionsConfiguration.cs b/src/OrchardCore/OrchardCore.Abstractions/Extensions/JsonSerializerOptionsConfiguration.cs new file mode 100644 index 00000000000..e938e2a1c61 --- /dev/null +++ b/src/OrchardCore/OrchardCore.Abstractions/Extensions/JsonSerializerOptionsConfiguration.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; +using Microsoft.Extensions.Options; +using OrchardCore.Json; +using OrchardCore.Json.Serialization; + +namespace OrchardCore.Extensions; + +public class JsonSerializerOptionsConfiguration : IConfigureOptions +{ + private readonly IEnumerable _typeInfoResolvers; + private readonly IOptions _derivedTypesOptions; + + public JsonSerializerOptionsConfiguration( + IEnumerable typeInfoResolvers, + IOptions derivedTypesOptions) + { + _typeInfoResolvers = typeInfoResolvers; + _derivedTypesOptions = derivedTypesOptions; + } + + public void Configure(JsonSerializerOptions options) + { + options.DefaultIgnoreCondition = JOptions.Base.DefaultIgnoreCondition; + options.ReferenceHandler = JOptions.Base.ReferenceHandler; + options.ReadCommentHandling = JOptions.Base.ReadCommentHandling; + options.PropertyNameCaseInsensitive = JOptions.Base.PropertyNameCaseInsensitive; + options.AllowTrailingCommas = JOptions.Base.AllowTrailingCommas; + options.WriteIndented = JOptions.Base.WriteIndented; + + foreach (var resolver in _typeInfoResolvers) + { + options.TypeInfoResolverChain.Add(resolver); + } + + options.TypeInfoResolverChain.Add(new PolymorphicJsonTypeInfoResolver(_derivedTypesOptions.Value)); + options.Converters.Add(DynamicJsonConverter.Instance); + options.Converters.Add(PathStringJsonConverter.Instance); + } +} diff --git a/src/OrchardCore/OrchardCore.Abstractions/Json/DefaultJsonSerializer.cs b/src/OrchardCore/OrchardCore.Abstractions/Json/DefaultJsonSerializer.cs new file mode 100644 index 00000000000..09350b2e870 --- /dev/null +++ b/src/OrchardCore/OrchardCore.Abstractions/Json/DefaultJsonSerializer.cs @@ -0,0 +1,27 @@ +using System; +using System.Text.Json; +using Microsoft.Extensions.Options; + +namespace OrchardCore.Json; + +public class DefaultJsonSerializer : IJsonSerializer +{ + private readonly JsonSerializerOptions _options; + + public DefaultJsonSerializer(IOptions options) + { + _options = options.Value; + } + + public object Deserialize(string content, Type type) + => JsonSerializer.Deserialize(content, type, _options); + + public T Deserialize(string content) + => JsonSerializer.Deserialize(content, _options); + + public string Serialize(object item) + => JsonSerializer.Serialize(item, _options); + + public string Serialize(T item) + => JsonSerializer.Serialize(item, _options); +} diff --git a/src/OrchardCore/OrchardCore.Abstractions/Json/IJsonSerializer.cs b/src/OrchardCore/OrchardCore.Abstractions/Json/IJsonSerializer.cs new file mode 100644 index 00000000000..1c6ea7914c9 --- /dev/null +++ b/src/OrchardCore/OrchardCore.Abstractions/Json/IJsonSerializer.cs @@ -0,0 +1,35 @@ +using System; + +namespace OrchardCore.Json; + +public interface IJsonSerializer +{ + /// + /// Serializes an object into a . + /// + /// The object to serialize. + /// The serialized object. + string Serialize(object item); + + /// + /// Serializes an object of a given type into a . + /// + /// The object to serialize. + /// The serialized object. + string Serialize(T item); + + /// + /// Deserializes an object from a string. + /// + /// The instance representing the object to deserialize. + /// The type of the object to deserialize. + /// The deserialized object. + object Deserialize(string content, Type type); + + /// + /// Deserializes an object from a string. + /// + /// The instance representing the object to deserialize. + /// The deserialized object. + T Deserialize(string content); +} diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/DefaultJsonContentSerializer.cs b/src/OrchardCore/OrchardCore.Data.YesSql/DefaultJsonContentSerializer.cs index 1758f2834b6..e283fce62e1 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/DefaultJsonContentSerializer.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/DefaultJsonContentSerializer.cs @@ -1,41 +1,20 @@ using System; -using System.Collections.Generic; -using System.Text.Json; -using System.Text.Json.Serialization.Metadata; -using OrchardCore.Json.Serialization; +using OrchardCore.Json; -namespace YesSql.Serialization -{ - public class DefaultJsonContentSerializer : IContentSerializer - { - private readonly JsonSerializerOptions _options; - - public DefaultJsonContentSerializer() - { - _options = new(JOptions.Base); - _options.Converters.Add(System.Text.Json.Serialization.DynamicJsonConverter.Instance); - _options.Converters.Add(PathStringJsonConverter.Instance); - } - - public DefaultJsonContentSerializer(IEnumerable typeInfoResolvers) - { - _options = new(JOptions.Base); - foreach (var resolver in typeInfoResolvers) - { - _options.TypeInfoResolverChain.Add(resolver); - } - - _options.Converters.Add(System.Text.Json.Serialization.DynamicJsonConverter.Instance); - _options.Converters.Add(PathStringJsonConverter.Instance); - } +namespace YesSql.Serialization; - public DefaultJsonContentSerializer(JsonSerializerOptions options) => _options = options; +public class DefaultJsonContentSerializer : IContentSerializer +{ + private readonly IJsonSerializer _jsonSerializer; - public object Deserialize(string content, Type type) - => JsonSerializer.Deserialize(content, type, _options); + public DefaultJsonContentSerializer(IJsonSerializer jsonSerializer) + { + _jsonSerializer = jsonSerializer; + } - public dynamic DeserializeDynamic(string content) => JsonSerializer.Deserialize(content, _options); + public object Deserialize(string content, Type type) + => _jsonSerializer.Deserialize(content, type); - public string Serialize(object item) => JsonSerializer.Serialize(item, _options); - } + public string Serialize(object item) + => _jsonSerializer.Serialize(item); } diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs index 3c80b76df40..be957bc2950 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs @@ -3,8 +3,6 @@ using System.Data; using System.IO; using System.Linq; -using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OrchardCore.Data; @@ -182,9 +180,7 @@ private static YesSql.Configuration GetStoreConfiguration(IServiceProvider sp, Y var tableNameFactory = sp.GetRequiredService(); var loggerFactory = sp.GetRequiredService(); - var typeInfoResolvers = sp.GetServices().ToList(); - var derivedTypesOptions = sp.GetService>(); - typeInfoResolvers.Add(new PolymorphicJsonTypeInfoResolver(derivedTypesOptions.Value)); + var jsonSerializer = sp.GetRequiredService(); var storeConfiguration = new YesSql.Configuration { @@ -193,7 +189,7 @@ private static YesSql.Configuration GetStoreConfiguration(IServiceProvider sp, Y TableNameConvention = tableNameFactory.Create(databaseTableOptions), IdentityColumnSize = Enum.Parse(databaseTableOptions.IdentityColumnSize), Logger = loggerFactory.CreateLogger("YesSql"), - ContentSerializer = new DefaultJsonContentSerializer(typeInfoResolvers) + ContentSerializer = new DefaultJsonContentSerializer(jsonSerializer) }; if (yesSqlOptions.IdGenerator != null) diff --git a/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs b/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs index f98b0e12209..de8daeec459 100644 --- a/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs +++ b/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs @@ -1,6 +1,8 @@ using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; namespace OrchardCore.Settings.Deployment @@ -8,10 +10,14 @@ namespace OrchardCore.Settings.Deployment public class SiteSettingsPropertyDeploymentSource : IDeploymentSource where TModel : class, new() { private readonly ISiteService _siteService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public SiteSettingsPropertyDeploymentSource(ISiteService siteService) + public SiteSettingsPropertyDeploymentSource( + ISiteService siteService, + IOptions jsonSerializerOptions) { _siteService = siteService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -25,7 +31,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var siteSettings = await _siteService.GetSiteSettingsAsync(); var settingJPropertyName = typeof(TModel).Name; - var settingJPropertyValue = JObject.FromObject(siteSettings.As()); + var settingJPropertyValue = JObject.FromObject(siteSettings.As(), _jsonSerializerOptions); var settingsStepJObject = result.Steps.FirstOrDefault(s => s["name"]?.ToString() == "Settings"); if (settingsStepJObject != null) diff --git a/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs b/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs index 27d408d61ed..645b6753742 100644 --- a/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs +++ b/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Net.Http; +using System.Text.Json; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; @@ -28,6 +29,8 @@ using OrchardCore.Environment.Shell.Builders; using OrchardCore.Environment.Shell.Configuration; using OrchardCore.Environment.Shell.Descriptor.Models; +using OrchardCore.Extensions; +using OrchardCore.Json; using OrchardCore.Localization; using OrchardCore.Locking; using OrchardCore.Locking.Distributed; @@ -152,6 +155,9 @@ private static void AddDefaultServices(OrchardCoreBuilder builder) services.AddSingleton(); + services.AddTransient, JsonSerializerOptionsConfiguration>(); + services.AddTransient(); + services.AddScoped(); services.AddSingleton(); diff --git a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs index 626640b937c..721b8988a59 100644 --- a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs +++ b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs @@ -1,3 +1,4 @@ +using System.Text.Json; using System.Text.Json.Nodes; using GraphQL; using GraphQL.Execution; @@ -11,6 +12,8 @@ using OrchardCore.ContentManagement.Records; using OrchardCore.Data; using OrchardCore.Environment.Shell; +using OrchardCore.Json; +using OrchardCore.Json.Serialization; using YesSql.Indexes; using YesSql.Provider.Sqlite; using YesSql.Serialization; @@ -36,8 +39,22 @@ public async Task InitializeAsync() _prefix = "tp"; _prefixedStore = await StoreFactory.CreateAndInitializeAsync(new Configuration().UseSqLite(string.Format(connectionStringTemplate, _tempFilename + _prefix)).SetTablePrefix(_prefix + "_")); - _store.Configuration.ContentSerializer = new DefaultJsonContentSerializer(); - _prefixedStore.Configuration.ContentSerializer = new DefaultJsonContentSerializer(); + var jsonDerivedTypesOptions = new JsonDerivedTypesOptions(); + + var jsonOptions = new JsonSerializerOptions(JOptions.Base); + jsonOptions.TypeInfoResolverChain.Add(new System.Text.Json.Serialization.PolymorphicJsonTypeInfoResolver(jsonDerivedTypesOptions)); + jsonOptions.Converters.Add(DynamicJsonConverter.Instance); + jsonOptions.Converters.Add(PathStringJsonConverter.Instance); + + var jsonSerializerOptions = new Mock>(); + jsonSerializerOptions.Setup(x => x.Value) + .Returns(jsonOptions); + + var jsonSerializer = new DefaultJsonSerializer(jsonSerializerOptions.Object); + var contentSerializer = new DefaultJsonContentSerializer(jsonSerializer); + + _store.Configuration.ContentSerializer = contentSerializer; + _prefixedStore.Configuration.ContentSerializer = contentSerializer; await CreateTablesAsync(_store); await CreateTablesAsync(_prefixedStore); @@ -141,7 +158,7 @@ public async Task ShouldFilterByContentItemIndex() context.Arguments["where"] = new ArgumentValue(JObject.Parse("{ \"contentItemId\": \"1\" }"), ArgumentSource.Variable); var dogs = await ((LockedAsyncFieldResolver>)type.Resolver) - .ResolveAsync(context) as IEnumerable; + .ResolveAsync(context) as IEnumerable; Assert.Single(dogs); Assert.Equal("doug", dogs.First().As().Name); diff --git a/test/OrchardCore.Tests/Modules/OrchardCore.OpenId/OpenIdServerDeploymentSourceTests.cs b/test/OrchardCore.Tests/Modules/OrchardCore.OpenId/OpenIdServerDeploymentSourceTests.cs index 8cc39a4d739..60f0d6043b7 100644 --- a/test/OrchardCore.Tests/Modules/OrchardCore.OpenId/OpenIdServerDeploymentSourceTests.cs +++ b/test/OrchardCore.Tests/Modules/OrchardCore.OpenId/OpenIdServerDeploymentSourceTests.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using OrchardCore.Deployment; +using OrchardCore.Json.Serialization; using OrchardCore.OpenId.Deployment; using OrchardCore.OpenId.Recipes; using OrchardCore.OpenId.Services; @@ -93,7 +95,15 @@ public async Task ServerDeploymentSourceIsReadableByRecipe() var descriptor = new RecipeDescriptor(); var result = new DeploymentPlanResult(fileBuilder, descriptor); - var deploymentSource = new OpenIdServerDeploymentSource(deployServerServiceMock.Object); + var jsonOptions = new JsonSerializerOptions(JOptions.Base); + jsonOptions.Converters.Add(System.Text.Json.Serialization.DynamicJsonConverter.Instance); + jsonOptions.Converters.Add(PathStringJsonConverter.Instance); + + var jsonSerializerOptions = new Mock>(); + jsonSerializerOptions.Setup(x => x.Value) + .Returns(jsonOptions); + + var deploymentSource = new OpenIdServerDeploymentSource(deployServerServiceMock.Object, jsonSerializerOptions.Object); // Act await deploymentSource.ProcessDeploymentStepAsync(new OpenIdServerDeploymentStep(), result); From 3b3a7d0986bdc02a76a23f5b10d689941b0113e3 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 15 Feb 2024 11:57:15 -0800 Subject: [PATCH 02/11] address feedback --- .../JsonSerializerOptionsConfiguration.cs | 17 +++------ .../Json/DefaultJsonSerializer.cs | 27 -------------- .../Json/IJsonSerializer.cs | 35 ------------------- .../DefaultJsonContentSerializer.cs | 34 +++++++++++------- .../OrchardCoreBuilderExtensions.cs | 6 ++-- .../Extensions/ServiceCollectionExtensions.cs | 2 -- .../GraphQL/ContentItemsFieldTypeTests.cs | 3 +- 7 files changed, 29 insertions(+), 95 deletions(-) delete mode 100644 src/OrchardCore/OrchardCore.Abstractions/Json/DefaultJsonSerializer.cs delete mode 100644 src/OrchardCore/OrchardCore.Abstractions/Json/IJsonSerializer.cs diff --git a/src/OrchardCore/OrchardCore.Abstractions/Extensions/JsonSerializerOptionsConfiguration.cs b/src/OrchardCore/OrchardCore.Abstractions/Extensions/JsonSerializerOptionsConfiguration.cs index e938e2a1c61..245ba42b3fa 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Extensions/JsonSerializerOptionsConfiguration.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Extensions/JsonSerializerOptionsConfiguration.cs @@ -1,7 +1,5 @@ -using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; using Microsoft.Extensions.Options; using OrchardCore.Json; using OrchardCore.Json.Serialization; @@ -10,32 +8,25 @@ namespace OrchardCore.Extensions; public class JsonSerializerOptionsConfiguration : IConfigureOptions { - private readonly IEnumerable _typeInfoResolvers; - private readonly IOptions _derivedTypesOptions; + private readonly JsonDerivedTypesOptions _derivedTypesOptions; public JsonSerializerOptionsConfiguration( - IEnumerable typeInfoResolvers, IOptions derivedTypesOptions) { - _typeInfoResolvers = typeInfoResolvers; - _derivedTypesOptions = derivedTypesOptions; + _derivedTypesOptions = derivedTypesOptions.Value; } public void Configure(JsonSerializerOptions options) { options.DefaultIgnoreCondition = JOptions.Base.DefaultIgnoreCondition; + options.ReferenceHandler = JOptions.Base.ReferenceHandler; options.ReadCommentHandling = JOptions.Base.ReadCommentHandling; options.PropertyNameCaseInsensitive = JOptions.Base.PropertyNameCaseInsensitive; options.AllowTrailingCommas = JOptions.Base.AllowTrailingCommas; options.WriteIndented = JOptions.Base.WriteIndented; - foreach (var resolver in _typeInfoResolvers) - { - options.TypeInfoResolverChain.Add(resolver); - } - - options.TypeInfoResolverChain.Add(new PolymorphicJsonTypeInfoResolver(_derivedTypesOptions.Value)); + options.TypeInfoResolverChain.Add(new PolymorphicJsonTypeInfoResolver(_derivedTypesOptions)); options.Converters.Add(DynamicJsonConverter.Instance); options.Converters.Add(PathStringJsonConverter.Instance); } diff --git a/src/OrchardCore/OrchardCore.Abstractions/Json/DefaultJsonSerializer.cs b/src/OrchardCore/OrchardCore.Abstractions/Json/DefaultJsonSerializer.cs deleted file mode 100644 index 09350b2e870..00000000000 --- a/src/OrchardCore/OrchardCore.Abstractions/Json/DefaultJsonSerializer.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Text.Json; -using Microsoft.Extensions.Options; - -namespace OrchardCore.Json; - -public class DefaultJsonSerializer : IJsonSerializer -{ - private readonly JsonSerializerOptions _options; - - public DefaultJsonSerializer(IOptions options) - { - _options = options.Value; - } - - public object Deserialize(string content, Type type) - => JsonSerializer.Deserialize(content, type, _options); - - public T Deserialize(string content) - => JsonSerializer.Deserialize(content, _options); - - public string Serialize(object item) - => JsonSerializer.Serialize(item, _options); - - public string Serialize(T item) - => JsonSerializer.Serialize(item, _options); -} diff --git a/src/OrchardCore/OrchardCore.Abstractions/Json/IJsonSerializer.cs b/src/OrchardCore/OrchardCore.Abstractions/Json/IJsonSerializer.cs deleted file mode 100644 index 1c6ea7914c9..00000000000 --- a/src/OrchardCore/OrchardCore.Abstractions/Json/IJsonSerializer.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; - -namespace OrchardCore.Json; - -public interface IJsonSerializer -{ - /// - /// Serializes an object into a . - /// - /// The object to serialize. - /// The serialized object. - string Serialize(object item); - - /// - /// Serializes an object of a given type into a . - /// - /// The object to serialize. - /// The serialized object. - string Serialize(T item); - - /// - /// Deserializes an object from a string. - /// - /// The instance representing the object to deserialize. - /// The type of the object to deserialize. - /// The deserialized object. - object Deserialize(string content, Type type); - - /// - /// Deserializes an object from a string. - /// - /// The instance representing the object to deserialize. - /// The deserialized object. - T Deserialize(string content); -} diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/DefaultJsonContentSerializer.cs b/src/OrchardCore/OrchardCore.Data.YesSql/DefaultJsonContentSerializer.cs index e283fce62e1..d62507cb738 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/DefaultJsonContentSerializer.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/DefaultJsonContentSerializer.cs @@ -1,20 +1,28 @@ using System; -using OrchardCore.Json; +using System.Text.Json; +using Microsoft.Extensions.Options; -namespace YesSql.Serialization; - -public class DefaultJsonContentSerializer : IContentSerializer +namespace YesSql.Serialization { - private readonly IJsonSerializer _jsonSerializer; - - public DefaultJsonContentSerializer(IJsonSerializer jsonSerializer) + public class DefaultJsonContentSerializer : IContentSerializer { - _jsonSerializer = jsonSerializer; - } + private readonly JsonSerializerOptions _options; + + public DefaultJsonContentSerializer(IOptions options) + { + _options = options.Value; + } - public object Deserialize(string content, Type type) - => _jsonSerializer.Deserialize(content, type); + public DefaultJsonContentSerializer(JsonSerializerOptions options) + => _options = options; - public string Serialize(object item) - => _jsonSerializer.Serialize(item); + public object Deserialize(string content, Type type) + => JsonSerializer.Deserialize(content, type, _options); + + public dynamic DeserializeDynamic(string content) + => JsonSerializer.Deserialize(content, _options); + + public string Serialize(object item) + => JsonSerializer.Serialize(item, _options); + } } diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs index be957bc2950..d30376f643f 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs @@ -3,6 +3,7 @@ using System.Data; using System.IO; using System.Linq; +using System.Text.Json; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OrchardCore.Data; @@ -12,7 +13,6 @@ using OrchardCore.Environment.Shell; using OrchardCore.Environment.Shell.Removing; using OrchardCore.Environment.Shell.Scope; -using OrchardCore.Json; using OrchardCore.Modules; using YesSql; using YesSql.Indexes; @@ -180,7 +180,7 @@ private static YesSql.Configuration GetStoreConfiguration(IServiceProvider sp, Y var tableNameFactory = sp.GetRequiredService(); var loggerFactory = sp.GetRequiredService(); - var jsonSerializer = sp.GetRequiredService(); + var serializerOptions = sp.GetRequiredService>(); var storeConfiguration = new YesSql.Configuration { @@ -189,7 +189,7 @@ private static YesSql.Configuration GetStoreConfiguration(IServiceProvider sp, Y TableNameConvention = tableNameFactory.Create(databaseTableOptions), IdentityColumnSize = Enum.Parse(databaseTableOptions.IdentityColumnSize), Logger = loggerFactory.CreateLogger("YesSql"), - ContentSerializer = new DefaultJsonContentSerializer(jsonSerializer) + ContentSerializer = new DefaultJsonContentSerializer(serializerOptions.Value) }; if (yesSqlOptions.IdGenerator != null) diff --git a/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs b/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs index 645b6753742..f3bf77e1cea 100644 --- a/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs +++ b/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs @@ -30,7 +30,6 @@ using OrchardCore.Environment.Shell.Configuration; using OrchardCore.Environment.Shell.Descriptor.Models; using OrchardCore.Extensions; -using OrchardCore.Json; using OrchardCore.Localization; using OrchardCore.Locking; using OrchardCore.Locking.Distributed; @@ -156,7 +155,6 @@ private static void AddDefaultServices(OrchardCoreBuilder builder) services.AddSingleton(); services.AddTransient, JsonSerializerOptionsConfiguration>(); - services.AddTransient(); services.AddScoped(); services.AddSingleton(); diff --git a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs index 721b8988a59..34fc2f52d9f 100644 --- a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs +++ b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs @@ -50,8 +50,7 @@ public async Task InitializeAsync() jsonSerializerOptions.Setup(x => x.Value) .Returns(jsonOptions); - var jsonSerializer = new DefaultJsonSerializer(jsonSerializerOptions.Object); - var contentSerializer = new DefaultJsonContentSerializer(jsonSerializer); + var contentSerializer = new DefaultJsonContentSerializer(jsonSerializerOptions.Object); _store.Configuration.ContentSerializer = contentSerializer; _prefixedStore.Configuration.ContentSerializer = contentSerializer; From 8d3ae1348333cea2adc515c6bd17a77f2c6beb69 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 15 Feb 2024 17:39:15 -0800 Subject: [PATCH 03/11] Update app FromObject() --- .../Recipes/LuceneRecipeEventHandler.cs | 11 ++++++++++- .../AuditTrailContentEventDisplayDriver.cs | 17 ++++++++++++----- .../Deployment/Download/DownloadController.cs | 11 ++++++++--- .../OrchardCore.Cors/Services/CorsService.cs | 10 ++++++++-- .../Drivers/CustomSettingsDisplayDriver.cs | 9 +++++++-- .../Login/Services/FacebookLoginService.cs | 9 +++++++-- .../Services/FacebookService.cs | 9 +++++++-- .../Deployment/AllLayersDeploymentSource.cs | 8 ++++---- .../Controllers/AdminController.cs | 9 +++++++-- .../Services/OpenIdClientService.cs | 9 +++++++-- .../Services/OpenIdServerService.cs | 7 ++++++- .../Services/OpenIdValidationService.cs | 7 ++++++- .../OrchardCore.Queries/Sql/SqlQuerySource.cs | 6 +++++- .../Deployment/AllRolesDeploymentSource.cs | 11 +++++++++-- .../Deployment/LuceneIndexDeploymentSource.cs | 10 ++++++++-- .../LuceneSettingsDeploymentSource.cs | 10 ++++++++-- .../SearchSettingsDeploymentSource.cs | 10 ++++++++-- .../Deployment/SiteSettingsDeploymentSource.cs | 10 ++++++++-- .../Controllers/AdminController.cs | 7 ++++++- .../Drivers/TaxonomyPartDisplayDriver.cs | 17 ++++++++++++----- .../AllAdminTemplatesDeploymentSource.cs | 12 +++++++++--- .../AllFeatureProfilesDeploymentSource.cs | 10 ++++++++-- .../Drivers/CustomUserSettingsDisplayDriver.cs | 7 ++++++- .../Services/WorkflowManager.cs | 11 ++++++++--- .../DefaultContentManager.cs | 9 +++++++-- .../Documents/DocumentEntityManager.cs | 13 ++++++++++--- .../ParametersMethodProvider.cs | 5 +++-- .../Services/RecipeExecutor.cs | 6 +++++- .../AzureAISearchIndexDeploymentSource.cs | 7 +++++-- .../AzureAISearchSettingsDeploymentSource.cs | 7 +++++-- .../Deployment/ElasticIndexDeploymentSource.cs | 10 ++++++++-- .../ElasticSettingsDeploymentSource.cs | 10 ++++++++-- 32 files changed, 235 insertions(+), 69 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs index 64a7d041392..515fd44e107 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata.Records; using OrchardCore.Recipes.Events; using OrchardCore.Recipes.Models; @@ -11,6 +13,13 @@ namespace OrchardCore.ContentTypes /// public class LuceneRecipeEventHandler : IRecipeEventHandler { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public LuceneRecipeEventHandler(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public RecipeExecutionContext Context { get; private set; } public Task RecipeStepExecutedAsync(RecipeExecutionContext context) => Task.CompletedTask; @@ -72,7 +81,7 @@ public Task RecipeStepExecutingAsync(RecipeExecutionContext context) } } - context.Step = JObject.FromObject(step); + context.Step = JObject.FromObject(step, _jsonSerializerOptions); } return Task.CompletedTask; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Drivers/AuditTrailContentEventDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Drivers/AuditTrailContentEventDisplayDriver.cs index 4baba6ce656..1bb69aa9e37 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Drivers/AuditTrailContentEventDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Drivers/AuditTrailContentEventDisplayDriver.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.AuditTrail.Drivers; using OrchardCore.AuditTrail.Indexes; using OrchardCore.AuditTrail.Models; @@ -21,11 +23,16 @@ public class AuditTrailContentEventDisplayDriver : AuditTrailEventSectionDisplay private readonly Dictionary _latestVersionId = []; private readonly IAuditTrailManager _auditTrailManager; private readonly ISession _session; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AuditTrailContentEventDisplayDriver(IAuditTrailManager auditTrailManager, ISession session) + public AuditTrailContentEventDisplayDriver( + IAuditTrailManager auditTrailManager, + ISession session, + IOptions jsonSerializerOptions) { _auditTrailManager = auditTrailManager; _session = session; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public override async Task DisplayAsync(AuditTrailEvent auditTrailEvent, AuditTrailContentEvent contentEvent, BuildDisplayContext context) @@ -67,8 +74,8 @@ public override async Task DisplayAsync(AuditTrailEvent auditTra if (previousContentItem != null) { - var current = JObject.FromObject(contentEvent.ContentItem); - var previous = JObject.FromObject(previousContentItem); + var current = JObject.FromObject(contentEvent.ContentItem, _jsonSerializerOptions); + var previous = JObject.FromObject(previousContentItem, _jsonSerializerOptions); previous.Remove(nameof(AuditTrailPart)); current.Remove(nameof(AuditTrailPart)); @@ -94,8 +101,8 @@ public override async Task DisplayAsync(AuditTrailEvent auditTra if (previousContentItem != null) { - var current = JObject.FromObject(contentEvent.ContentItem); - var previous = JObject.FromObject(previousContentItem); + var current = JObject.FromObject(contentEvent.ContentItem, _jsonSerializerOptions); + var previous = JObject.FromObject(previousContentItem, _jsonSerializerOptions); previous.Remove(nameof(AuditTrailPart)); current.Remove(nameof(AuditTrailPart)); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/Download/DownloadController.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/Download/DownloadController.cs index 376f143cb7a..21a14980420 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/Download/DownloadController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/Download/DownloadController.cs @@ -1,8 +1,10 @@ using System.Text; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using OrchardCore.Admin; using OrchardCore.ContentManagement; using OrchardCore.Modules; @@ -15,14 +17,17 @@ public class DownloadController : Controller { private readonly IAuthorizationService _authorizationService; private readonly IContentManager _contentManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; public DownloadController( IAuthorizationService authorizationService, - IContentManager contentManager + IContentManager contentManager, + IOptions jsonSerializerOptions ) { _authorizationService = authorizationService; _contentManager = contentManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } [HttpGet] @@ -50,7 +55,7 @@ public async Task Display(string contentItemId, bool latest = fal var model = new DisplayJsonContentItemViewModel { ContentItem = contentItem, - ContentItemJson = JObject.FromObject(contentItem).ToString() + ContentItemJson = JObject.FromObject(contentItem, _jsonSerializerOptions).ToString() }; return View(model); @@ -78,7 +83,7 @@ public async Task Download(string contentItemId, bool latest = fa return Forbid(); } - var jItem = JObject.FromObject(contentItem); + var jItem = JObject.FromObject(contentItem, _jsonSerializerOptions); return File(Encoding.UTF8.GetBytes(jItem.ToString()), "application/json", $"{contentItem.ContentItemId}.json"); } diff --git a/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs b/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs index 25d33fc0161..3133574a80c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Cors.Settings; using OrchardCore.Settings; @@ -8,10 +10,14 @@ namespace OrchardCore.Cors.Services public class CorsService { private readonly ISiteService _siteService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public CorsService(ISiteService siteService) + public CorsService( + ISiteService siteService, + IOptions jsonSerializerOptions) { _siteService = siteService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task GetSettingsAsync() @@ -23,7 +29,7 @@ public async Task GetSettingsAsync() internal async Task UpdateSettingsAsync(CorsSettings corsSettings) { var siteSettings = await _siteService.LoadSiteSettingsAsync(); - siteSettings.Properties[nameof(CorsSettings)] = JObject.FromObject(corsSettings); + siteSettings.Properties[nameof(CorsSettings)] = JObject.FromObject(corsSettings, _jsonSerializerOptions); await _siteService.UpdateSiteSettingsAsync(siteSettings); } } diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Drivers/CustomSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Drivers/CustomSettingsDisplayDriver.cs index d0465cd3292..6f88c9a6f95 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Drivers/CustomSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Drivers/CustomSettingsDisplayDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Display; using OrchardCore.CustomSettings.Services; using OrchardCore.CustomSettings.ViewModels; @@ -17,13 +19,16 @@ public class CustomSettingsDisplayDriver : DisplayDriver { private readonly CustomSettingsService _customSettingsService; private readonly IContentItemDisplayManager _contentItemDisplayManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; public CustomSettingsDisplayDriver( CustomSettingsService customSettingsService, - IContentItemDisplayManager contentItemDisplayManager) + IContentItemDisplayManager contentItemDisplayManager, + IOptions jsonSerializerOptions) { _customSettingsService = customSettingsService; _contentItemDisplayManager = contentItemDisplayManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public override async Task EditAsync(ISite site, BuildEditorContext context) @@ -68,7 +73,7 @@ public override async Task UpdateAsync(ISite site, UpdateEditorC await _contentItemDisplayManager.UpdateEditorAsync(contentItem, context.Updater, isNew); - site.Properties[contentTypeDefinition.Name] = JObject.FromObject(contentItem); + site.Properties[contentTypeDefinition.Name] = JObject.FromObject(contentItem, _jsonSerializerOptions); return await EditAsync(site, context); } diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs index a992d8151b5..8ac80f778b0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.ComponentModel.DataAnnotations; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Facebook.Login.Settings; using OrchardCore.Settings; @@ -12,11 +14,14 @@ namespace OrchardCore.Facebook.Login.Services public class FacebookLoginService : IFacebookLoginService { private readonly ISiteService _siteService; + private readonly JsonSerializerOptions _jsonSerializerOptions; public FacebookLoginService( - ISiteService siteService) + ISiteService siteService, + IOptions jsonSerializerOptions) { _siteService = siteService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task GetSettingsAsync() @@ -36,7 +41,7 @@ public async Task UpdateSettingsAsync(FacebookLoginSettings settings) ArgumentNullException.ThrowIfNull(settings); var container = await _siteService.LoadSiteSettingsAsync(); - container.Properties[nameof(FacebookLoginSettings)] = JObject.FromObject(settings); + container.Properties[nameof(FacebookLoginSettings)] = JObject.FromObject(settings, _jsonSerializerOptions); await _siteService.UpdateSiteSettingsAsync(container); } diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs index 0679fbb3009..8832c35cb7b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.Facebook.Settings; using OrchardCore.Settings; @@ -13,13 +15,16 @@ public class FacebookService : IFacebookService { private readonly ISiteService _siteService; protected readonly IStringLocalizer S; + private readonly JsonSerializerOptions _jsonSerializerOptions; public FacebookService( ISiteService siteService, - IStringLocalizer stringLocalizer) + IStringLocalizer stringLocalizer, + IOptions jsonSerializerOptions) { _siteService = siteService; S = stringLocalizer; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task GetSettingsAsync() @@ -33,7 +38,7 @@ public async Task UpdateSettingsAsync(FacebookSettings settings) ArgumentNullException.ThrowIfNull(settings); var container = await _siteService.LoadSiteSettingsAsync(); - container.Properties[nameof(FacebookSettings)] = JObject.FromObject(settings); + container.Properties[nameof(FacebookSettings)] = JObject.FromObject(settings, _jsonSerializerOptions); await _siteService.UpdateSiteSettingsAsync(container); } diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs index b3ede9b408d..2edcdd46705 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs @@ -13,7 +13,7 @@ public class AllLayersDeploymentSource : IDeploymentSource { private readonly ILayerService _layerService; private readonly ISiteService _siteService; - private readonly JsonSerializerOptions _serializationOptions; + private readonly JsonSerializerOptions _jsonSerializerOptions; public AllLayersDeploymentSource( ILayerService layerService, @@ -24,7 +24,7 @@ public AllLayersDeploymentSource( _siteService = siteService; // The recipe step contains polymorphic types which need to be resolved - _serializationOptions = serializationOptions.Value; + _jsonSerializerOptions = serializationOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -41,7 +41,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "Layers", - ["Layers"] = JArray.FromObject(layers.Layers, _serializationOptions), + ["Layers"] = JArray.FromObject(layers.Layers, _jsonSerializerOptions), }); var siteSettings = await _siteService.GetSiteSettingsAsync(); @@ -50,7 +50,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "Settings", - ["LayerSettings"] = JObject.FromObject(siteSettings.As()), + ["LayerSettings"] = JObject.FromObject(siteSettings.As(), _jsonSerializerOptions), }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs index 5e2763c1d03..c539a79624f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs @@ -1,10 +1,12 @@ using System.Linq; +using System.Text.Json; 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 Microsoft.Extensions.Options; using OrchardCore.Admin; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; @@ -27,6 +29,7 @@ public class AdminController : Controller private readonly ISession _session; private readonly INotifier _notifier; protected readonly IHtmlLocalizer H; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IUpdateModelAccessor _updateModelAccessor; public AdminController( @@ -37,6 +40,7 @@ public AdminController( IContentDefinitionManager contentDefinitionManager, INotifier notifier, IHtmlLocalizer localizer, + IOptions jsonSerializerOptions, IUpdateModelAccessor updateModelAccessor) { _contentManager = contentManager; @@ -47,6 +51,7 @@ public AdminController( _notifier = notifier; _updateModelAccessor = updateModelAccessor; H = localizer; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task Create(string id, string menuContentItemId, string menuItemId) @@ -136,7 +141,7 @@ public async Task CreatePost(string id, string menuContentItemId, }; } - menuItems.Add(JObject.FromObject(contentItem)); + menuItems.Add(JObject.FromObject(contentItem, _jsonSerializerOptions)); } await _contentManager.SaveDraftAsync(menu); @@ -167,7 +172,7 @@ public async Task Edit(string menuContentItemId, string menuItemI return NotFound(); } - var contentItem = menuItem.ToObject(); + var contentItem = menuItem.ToObject(_jsonSerializerOptions); dynamic model = await _contentItemDisplayManager.BuildEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false); diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs index 6fad5099a0b..b393c069c87 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Immutable; using System.ComponentModel.DataAnnotations; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using OrchardCore.OpenId.Settings; using OrchardCore.Settings; @@ -14,13 +16,16 @@ public class OpenIdClientService : IOpenIdClientService { private readonly ISiteService _siteService; protected readonly IStringLocalizer S; + private readonly JsonSerializerOptions _jsonSerializerOptions; public OpenIdClientService( ISiteService siteService, - IStringLocalizer stringLocalizer) + IStringLocalizer stringLocalizer, + IOptions jsonSerializerOptions) { _siteService = siteService; S = stringLocalizer; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task GetSettingsAsync() @@ -40,7 +45,7 @@ public async Task UpdateSettingsAsync(OpenIdClientSettings settings) ArgumentNullException.ThrowIfNull(settings); var container = await _siteService.LoadSiteSettingsAsync(); - container.Properties[nameof(OpenIdClientSettings)] = JObject.FromObject(settings); + container.Properties[nameof(OpenIdClientSettings)] = JObject.FromObject(settings, _jsonSerializerOptions); await _siteService.UpdateSiteSettingsAsync(container); } diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs index 81b6f398c94..01c7eb42959 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs @@ -7,6 +7,7 @@ using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.AspNetCore.DataProtection; @@ -29,6 +30,8 @@ public class OpenIdServerService : IOpenIdServerService private readonly IOptionsMonitor _shellOptions; private readonly ShellSettings _shellSettings; private readonly ISiteService _siteService; + private readonly JsonSerializerOptions _jsonSerializerOptions; + protected readonly IStringLocalizer S; public OpenIdServerService( @@ -38,6 +41,7 @@ public OpenIdServerService( IOptionsMonitor shellOptions, ShellSettings shellSettings, ISiteService siteService, + IOptions jsonSerializerOptions, IStringLocalizer stringLocalizer) { _dataProtector = dataProtectionProvider.CreateProtector(nameof(OpenIdServerService)); @@ -46,6 +50,7 @@ public OpenIdServerService( _shellOptions = shellOptions; _shellSettings = shellSettings; _siteService = siteService; + _jsonSerializerOptions = jsonSerializerOptions.Value; S = stringLocalizer; } @@ -89,7 +94,7 @@ public async Task UpdateSettingsAsync(OpenIdServerSettings settings) ArgumentNullException.ThrowIfNull(settings); var container = await _siteService.LoadSiteSettingsAsync(); - container.Properties[nameof(OpenIdServerSettings)] = JObject.FromObject(settings); + container.Properties[nameof(OpenIdServerSettings)] = JObject.FromObject(settings, _jsonSerializerOptions); await _siteService.UpdateSiteSettingsAsync(container); } diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdValidationService.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdValidationService.cs index 4b17a6d5887..9d46ef87803 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdValidationService.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdValidationService.cs @@ -2,6 +2,7 @@ using System.Collections.Immutable; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; @@ -22,6 +23,8 @@ public class OpenIdValidationService : IOpenIdValidationService private readonly ShellSettings _shellSettings; private readonly IShellHost _shellHost; private readonly ISiteService _siteService; + private readonly JsonSerializerOptions _jsonSerializerOptions; + protected readonly IStringLocalizer S; public OpenIdValidationService( @@ -29,12 +32,14 @@ public OpenIdValidationService( ShellSettings shellSettings, IShellHost shellHost, ISiteService siteService, + IOptions jsonSerializerOptions, IStringLocalizer stringLocalizer) { _shellDescriptor = shellDescriptor; _shellSettings = shellSettings; _shellHost = shellHost; _siteService = siteService; + _jsonSerializerOptions = jsonSerializerOptions.Value; S = stringLocalizer; } @@ -75,7 +80,7 @@ public async Task UpdateSettingsAsync(OpenIdValidationSettings settings) ArgumentNullException.ThrowIfNull(settings); var container = await _siteService.LoadSiteSettingsAsync(); - container.Properties[nameof(OpenIdValidationSettings)] = JObject.FromObject(settings); + container.Properties[nameof(OpenIdValidationSettings)] = JObject.FromObject(settings, _jsonSerializerOptions); await _siteService.UpdateSiteSettingsAsync(container); } diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Sql/SqlQuerySource.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Sql/SqlQuerySource.cs index 555b43c186c..dac4c8d7120 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Sql/SqlQuerySource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Sql/SqlQuerySource.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Dapper; @@ -19,17 +20,20 @@ public class SqlQuerySource : IQuerySource private readonly ILiquidTemplateManager _liquidTemplateManager; private readonly IDbConnectionAccessor _dbConnectionAccessor; private readonly ISession _session; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly TemplateOptions _templateOptions; public SqlQuerySource( ILiquidTemplateManager liquidTemplateManager, IDbConnectionAccessor dbConnectionAccessor, ISession session, + IOptions jsonSerializerOptions, IOptions templateOptions) { _liquidTemplateManager = liquidTemplateManager; _dbConnectionAccessor = dbConnectionAccessor; _session = session; + _jsonSerializerOptions = jsonSerializerOptions.Value; _templateOptions = templateOptions.Value; } @@ -82,7 +86,7 @@ public async Task ExecuteQueryAsync(Query query, IDictionary(); foreach (var document in queryResults) { - results.Add(JObject.FromObject(document)); + results.Add(JObject.FromObject(document, _jsonSerializerOptions)); } sqlQueryResults.Items = results; diff --git a/src/OrchardCore.Modules/OrchardCore.Roles/Deployment/AllRolesDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Roles/Deployment/AllRolesDeploymentSource.cs index 80bf4a3c077..46e2e9c39a5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Roles/Deployment/AllRolesDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Roles/Deployment/AllRolesDeploymentSource.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Roles.Recipes; using OrchardCore.Security; @@ -14,11 +16,16 @@ namespace OrchardCore.Roles.Deployment public class AllRolesDeploymentSource : IDeploymentSource { private readonly RoleManager _roleManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IRoleService _roleService; - public AllRolesDeploymentSource(RoleManager roleManager, IRoleService roleService) + public AllRolesDeploymentSource( + RoleManager roleManager, + IOptions jsonSerializerOptions, + IRoleService roleService) { _roleManager = roleManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; _roleService = roleService; } @@ -48,7 +55,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan Name = currentRole.RoleName, Description = currentRole.RoleDescription, Permissions = currentRole.RoleClaims.Where(x => x.ClaimType == Permission.ClaimType).Select(x => x.ClaimValue).ToArray() - })); + }, _jsonSerializerOptions)); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Deployment/LuceneIndexDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Deployment/LuceneIndexDeploymentSource.cs index 6d0b56f9339..b2119fdc659 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Deployment/LuceneIndexDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Deployment/LuceneIndexDeploymentSource.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Search.Lucene.Model; @@ -10,10 +12,14 @@ namespace OrchardCore.Search.Lucene.Deployment public class LuceneIndexDeploymentSource : IDeploymentSource { private readonly LuceneIndexSettingsService _luceneIndexSettingsService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public LuceneIndexDeploymentSource(LuceneIndexSettingsService luceneIndexSettingsService) + public LuceneIndexDeploymentSource( + LuceneIndexSettingsService luceneIndexSettingsService, + IOptions jsonSerializerOptions) { _luceneIndexSettingsService = luceneIndexSettingsService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -39,7 +45,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan { index.IndexName, index }, }; - data.Add(JObject.FromObject(indexSettingsDict)); + data.Add(JObject.FromObject(indexSettingsDict, _jsonSerializerOptions)); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Deployment/LuceneSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Deployment/LuceneSettingsDeploymentSource.cs index 1dd1a929c3e..b307dbcb044 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Deployment/LuceneSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Deployment/LuceneSettingsDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; namespace OrchardCore.Search.Lucene.Deployment @@ -7,10 +9,14 @@ namespace OrchardCore.Search.Lucene.Deployment public class LuceneSettingsDeploymentSource : IDeploymentSource { private readonly LuceneIndexingService _luceneIndexingService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public LuceneSettingsDeploymentSource(LuceneIndexingService luceneIndexingService) + public LuceneSettingsDeploymentSource( + LuceneIndexingService luceneIndexingService, + IOptions jsonSerializerOptions) { _luceneIndexingService = luceneIndexingService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -28,7 +34,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "Settings", - ["LuceneSettings"] = JObject.FromObject(luceneSettings), + ["LuceneSettings"] = JObject.FromObject(luceneSettings, _jsonSerializerOptions), }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs index 392dc578ab3..29915f69a3c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Search.Models; using OrchardCore.Settings; @@ -9,10 +11,14 @@ namespace OrchardCore.Search.Deployment public class SearchSettingsDeploymentSource : IDeploymentSource { private readonly ISiteService _site; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public SearchSettingsDeploymentSource(ISiteService site) + public SearchSettingsDeploymentSource( + ISiteService site, + IOptions jsonSerializerOptions) { _site = site; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -30,7 +36,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "Settings", - ["SearchSettings"] = JObject.FromObject(searchSettings), + ["SearchSettings"] = JObject.FromObject(searchSettings, _jsonSerializerOptions), }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/Deployment/SiteSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Settings/Deployment/SiteSettingsDeploymentSource.cs index 8a09407607a..3462eb209eb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/Deployment/SiteSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/Deployment/SiteSettingsDeploymentSource.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; namespace OrchardCore.Settings.Deployment @@ -8,10 +10,14 @@ namespace OrchardCore.Settings.Deployment public class SiteSettingsDeploymentSource : IDeploymentSource { private readonly ISiteService _siteService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public SiteSettingsDeploymentSource(ISiteService siteService) + public SiteSettingsDeploymentSource( + ISiteService siteService, + IOptions jsonSerializerOptions) { _siteService = siteService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -87,7 +93,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan break; case "HomeRoute": - data.Add(nameof(ISite.HomeRoute), JObject.FromObject(site.HomeRoute)); + data.Add(nameof(ISite.HomeRoute), JObject.FromObject(site.HomeRoute, _jsonSerializerOptions)); break; case "CacheMode": diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs index 08b5ad0b717..2013e4c3005 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs @@ -1,10 +1,12 @@ using System.Linq; +using System.Text.Json; 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 Microsoft.Extensions.Options; using OrchardCore.Admin; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; @@ -27,6 +29,7 @@ public class AdminController : Controller private readonly ISession _session; protected readonly IHtmlLocalizer H; private readonly INotifier _notifier; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IUpdateModelAccessor _updateModelAccessor; public AdminController( @@ -36,6 +39,7 @@ public AdminController( IContentItemDisplayManager contentItemDisplayManager, IContentDefinitionManager contentDefinitionManager, INotifier notifier, + IOptions jsonSerializerOptions, IHtmlLocalizer localizer, IUpdateModelAccessor updateModelAccessor) { @@ -45,6 +49,7 @@ public AdminController( _contentDefinitionManager = contentDefinitionManager; _session = session; _notifier = notifier; + _jsonSerializerOptions = jsonSerializerOptions.Value; _updateModelAccessor = updateModelAccessor; H = localizer; } @@ -153,7 +158,7 @@ public async Task CreatePost(string id, string taxonomyContentIte parentTaxonomyItem["Terms"] = taxonomyItems = []; } - taxonomyItems.Add(JObject.FromObject(contentItem)); + taxonomyItems.Add(JObject.FromObject(contentItem, _jsonSerializerOptions)); } await _session.SaveAsync(taxonomy); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs index df668d7331f..dd186c779e6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs @@ -1,9 +1,11 @@ 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 Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.ContentManagement.Display.Models; @@ -19,9 +21,14 @@ public class TaxonomyPartDisplayDriver : ContentPartDisplayDriver { protected readonly IStringLocalizer S; - public TaxonomyPartDisplayDriver(IStringLocalizer stringLocalizer) + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public TaxonomyPartDisplayDriver( + IStringLocalizer stringLocalizer, + IOptions jsonSerializerOptions) { S = stringLocalizer; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public override IDisplayResult Display(TaxonomyPart part, BuildPartDisplayContext context) @@ -68,7 +75,7 @@ public override async Task UpdateAsync(TaxonomyPart part, IUpdat taxonomyItems.Add(ProcessItem(originalTaxonomyItems, item as JsonObject)); } - part.Terms = taxonomyItems.ToObject>(); + part.Terms = taxonomyItems.ToObject>(_jsonSerializerOptions); } part.TermContentType = model.TermContentType; @@ -80,7 +87,7 @@ public override async Task UpdateAsync(TaxonomyPart part, IUpdat /// /// Clone the content items at the specific index. /// - private static JsonObject GetTaxonomyItemAt(List taxonomyItems, int[] indexes) + private JsonObject GetTaxonomyItemAt(List taxonomyItems, int[] indexes) { ContentItem taxonomyItem = null; @@ -99,7 +106,7 @@ private static JsonObject GetTaxonomyItemAt(List taxonomyItems, int taxonomyItems = terms?.ToObject>(); } - var newObj = JObject.FromObject(taxonomyItem); + var newObj = JObject.FromObject(taxonomyItem, _jsonSerializerOptions); if (newObj["Terms"] != null) { @@ -109,7 +116,7 @@ private static JsonObject GetTaxonomyItemAt(List taxonomyItems, int return newObj; } - private static JsonObject ProcessItem(TaxonomyPart originalItems, JsonObject item) + private JsonObject ProcessItem(TaxonomyPart originalItems, JsonObject item) { var contentItem = GetTaxonomyItemAt(originalItems.Terms, item["index"].ToString().Split('-').Select(x => Convert.ToInt32(x)).ToArray()); diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllAdminTemplatesDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllAdminTemplatesDeploymentSource.cs index a7c3c0cd5c9..57bf54944a8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllAdminTemplatesDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/Deployment/AllAdminTemplatesDeploymentSource.cs @@ -1,6 +1,8 @@ using System.Text; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Templates.Models; using OrchardCore.Templates.Services; @@ -10,10 +12,14 @@ namespace OrchardCore.Templates.Deployment public class AllAdminTemplatesDeploymentSource : IDeploymentSource { private readonly AdminTemplatesManager _templatesManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllAdminTemplatesDeploymentSource(AdminTemplatesManager templatesManager) + public AllAdminTemplatesDeploymentSource( + AdminTemplatesManager templatesManager, + IOptions jsonSerializerOptions) { _templatesManager = templatesManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -35,14 +41,14 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var fileName = "AdminTemplates/" + template.Key.Replace("__", "-").Replace("_", ".") + ".liquid"; var templateValue = new Template { Description = template.Value.Description, Content = $"[file:text('{fileName}')]" }; await result.FileBuilder.SetFileAsync(fileName, Encoding.UTF8.GetBytes(template.Value.Content)); - templateObjects[template.Key] = JObject.FromObject(templateValue); + templateObjects[template.Key] = JObject.FromObject(templateValue, _jsonSerializerOptions); } } else { foreach (var template in templates.Templates) { - templateObjects[template.Key] = JObject.FromObject(template.Value); + templateObjects[template.Key] = JObject.FromObject(template.Value, _jsonSerializerOptions); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Deployment/AllFeatureProfilesDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Deployment/AllFeatureProfilesDeploymentSource.cs index b415fb40f8e..9835eb532f9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Deployment/AllFeatureProfilesDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Deployment/AllFeatureProfilesDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Tenants.Services; @@ -8,10 +10,14 @@ namespace OrchardCore.Tenants.Deployment public class AllFeatureProfilesDeploymentSource : IDeploymentSource { private readonly FeatureProfilesManager _featureProfilesManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AllFeatureProfilesDeploymentSource(FeatureProfilesManager featureProfilesManager) + public AllFeatureProfilesDeploymentSource( + FeatureProfilesManager featureProfilesManager, + IOptions jsonSerializerOptions) { _featureProfilesManager = featureProfilesManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -26,7 +32,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan foreach (var featureProfile in featureProfiles.FeatureProfiles) { - featureProfileObjects[featureProfile.Key] = JObject.FromObject(featureProfile.Value); + featureProfileObjects[featureProfile.Key] = JObject.FromObject(featureProfile.Value, _jsonSerializerOptions); } result.Steps.Add(new JsonObject diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/CustomUserSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/CustomUserSettingsDisplayDriver.cs index e0a71092b96..cd63702b4d6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/CustomUserSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/CustomUserSettingsDisplayDriver.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; using OrchardCore.ContentManagement.Metadata; @@ -22,6 +24,7 @@ public class CustomUserSettingsDisplayDriver : DisplayDriver private readonly IContentDefinitionManager _contentDefinitionManager; private readonly IContentManager _contentManager; private readonly IAuthorizationService _authorizationService; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IHttpContextAccessor _httpContextAccessor; public CustomUserSettingsDisplayDriver( @@ -29,12 +32,14 @@ public CustomUserSettingsDisplayDriver( IContentDefinitionManager contentDefinitionManager, IContentManager contentManager, IAuthorizationService authorizationService, + IOptions jsonSerializerOptions, IHttpContextAccessor httpContextAccessor) { _contentItemDisplayManager = contentItemDisplayManager; _contentDefinitionManager = contentDefinitionManager; _contentManager = contentManager; _authorizationService = authorizationService; + _jsonSerializerOptions = jsonSerializerOptions.Value; _httpContextAccessor = httpContextAccessor; } @@ -80,7 +85,7 @@ public override async Task UpdateAsync(User user, UpdateEditorCo var isNew = false; var contentItem = await GetUserSettingsAsync(user, contentTypeDefinition, () => isNew = true); await _contentItemDisplayManager.UpdateEditorAsync(contentItem, context.Updater, isNew, context.GroupId, Prefix); - user.Properties[contentTypeDefinition.Name] = JObject.FromObject(contentItem); + user.Properties[contentTypeDefinition.Name] = JObject.FromObject(contentItem, _jsonSerializerOptions); } return await EditAsync(user, context); diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/Services/WorkflowManager.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/Services/WorkflowManager.cs index 301096184a9..4dbe6869e72 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/Services/WorkflowManager.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/Services/WorkflowManager.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using OrchardCore.Locking.Distributed; using OrchardCore.Modules; using OrchardCore.Workflows.Activities; @@ -30,6 +32,7 @@ public class WorkflowManager : IWorkflowManager private readonly ILogger _logger; private readonly ILogger _missingActivityLogger; private readonly IStringLocalizer _missingActivityLocalizer; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IClock _clock; private readonly Dictionary _recursions = []; @@ -47,6 +50,7 @@ public WorkflowManager ILogger logger, ILogger missingActivityLogger, IStringLocalizer missingActivityLocalizer, + IOptions jsonSerializerOptions, IClock clock) { _activityLibrary = activityLibrary; @@ -59,6 +63,7 @@ public WorkflowManager _logger = logger; _missingActivityLogger = missingActivityLogger; _missingActivityLocalizer = missingActivityLocalizer; + _jsonSerializerOptions = jsonSerializerOptions.Value; _clock = clock; } @@ -73,7 +78,7 @@ public Workflow NewWorkflow(WorkflowType workflowType, string correlationId = nu State = JObject.FromObject(new WorkflowState { ActivityStates = workflowType.Activities.ToDictionary(x => x.ActivityId, x => x.Properties) - }), + }, _jsonSerializerOptions), CorrelationId = correlationId, LockTimeout = workflowType.LockTimeout, LockExpiration = workflowType.LockExpiration, @@ -90,7 +95,7 @@ public async Task CreateWorkflowExecutionContextAsync( ArgumentNullException.ThrowIfNull(workflow); - var state = workflow.State.ToObject(); + var state = workflow.State.ToObject(_jsonSerializerOptions); var activityQuery = await Task.WhenAll(workflowType.Activities.Select(x => { if (!state.ActivityStates.TryGetValue(x.ActivityId, out var activityState)) @@ -560,7 +565,7 @@ private async Task PersistAsync(WorkflowExecutionContext workflowContext) state.ExecutedActivities = workflowContext.ExecutedActivities.ToList(); state.ActivityStates = workflowContext.Activities.ToDictionary(x => x.Key, x => x.Value.Activity.Properties); - workflowContext.Workflow.State = JObject.FromObject(state); + workflowContext.Workflow.State = JObject.FromObject(state, _jsonSerializerOptions); await _workflowStore.SaveAsync(workflowContext.Workflow); } diff --git a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs index cb1bd57ac49..d1ffed01653 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement/DefaultContentManager.cs @@ -2,10 +2,12 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Settings; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.CompiledQueries; using OrchardCore.ContentManagement.Handlers; using OrchardCore.ContentManagement.Metadata; @@ -28,6 +30,7 @@ public class DefaultContentManager : IContentManager private readonly ISession _session; private readonly ILogger _logger; private readonly IContentManagerSession _contentManagerSession; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IContentItemIdGenerator _idGenerator; private readonly IClock _clock; @@ -37,6 +40,7 @@ public DefaultContentManager( IEnumerable handlers, ISession session, IContentItemIdGenerator idGenerator, + IOptions jsonSerializerOptions, ILogger logger, IClock clock) { @@ -46,6 +50,7 @@ public DefaultContentManager( _session = session; _idGenerator = idGenerator; _contentManagerSession = contentManagerSession; + _jsonSerializerOptions = jsonSerializerOptions.Value; _logger = logger; _clock = clock; } @@ -730,7 +735,7 @@ public async Task ImportAsync(IEnumerable contentItems) // would be further ahead, on a timeline, between the two. // var jImporting = JObject.FromObject(importingItem); - var jImporting = JObject.FromObject(importingItem); + var jImporting = JObject.FromObject(importingItem, _jsonSerializerOptions); // Removed Published and Latest from consideration when evaluating. // Otherwise an import of an unchanged (but published) version would overwrite a newer published version. @@ -738,7 +743,7 @@ public async Task ImportAsync(IEnumerable contentItems) jImporting.Remove(nameof(ContentItem.Latest)); // var jOriginal = JObject.FromObject(originalVersion); - var jOriginal = JObject.FromObject(originalVersion); + var jOriginal = JObject.FromObject(originalVersion, _jsonSerializerOptions); jOriginal.Remove(nameof(ContentItem.Published)); jOriginal.Remove(nameof(ContentItem.Latest)); diff --git a/src/OrchardCore/OrchardCore.Infrastructure/Documents/DocumentEntityManager.cs b/src/OrchardCore/OrchardCore.Infrastructure/Documents/DocumentEntityManager.cs index 14b7714994b..ae69c9e9a29 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure/Documents/DocumentEntityManager.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure/Documents/DocumentEntityManager.cs @@ -1,6 +1,7 @@ using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Data.Documents; namespace OrchardCore.Documents @@ -11,15 +12,21 @@ namespace OrchardCore.Documents public class DocumentEntityManager : IDocumentEntityManager where TDocumentEntity : class, IDocumentEntity, new() { private readonly IDocumentManager _documentManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public DocumentEntityManager(IDocumentManager documentManager) => _documentManager = documentManager; + public DocumentEntityManager(IDocumentManager documentManager, + IOptions jsonSerializerOptions) + { + _documentManager = documentManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; + } public async Task GetAsync(string key) where T : new() { var document = await _documentManager.GetOrCreateImmutableAsync(); if (document.Properties.TryGetPropertyValue(key, out var value)) { - return value.Deserialize(JOptions.Default); + return value.Deserialize(_jsonSerializerOptions); } return new T(); @@ -28,7 +35,7 @@ namespace OrchardCore.Documents public async Task SetAsync(string key, T value) where T : new() { var document = await _documentManager.GetOrCreateMutableAsync(); - document.Properties[key] = JObject.FromObject(value); + document.Properties[key] = JObject.FromObject(value, _jsonSerializerOptions); await _documentManager.UpdateAsync(document); } diff --git a/src/OrchardCore/OrchardCore.Recipes.Core/ParametersMethodProvider.cs b/src/OrchardCore/OrchardCore.Recipes.Core/ParametersMethodProvider.cs index 503db793984..dd54c88b5f3 100644 --- a/src/OrchardCore/OrchardCore.Recipes.Core/ParametersMethodProvider.cs +++ b/src/OrchardCore/OrchardCore.Recipes.Core/ParametersMethodProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Nodes; using OrchardCore.Scripting; @@ -9,9 +10,9 @@ public class ParametersMethodProvider : IGlobalMethodProvider { private readonly GlobalMethod _globalMethod; - public ParametersMethodProvider(object environment) + public ParametersMethodProvider(object environment, JsonSerializerOptions jsonSerializerOptions) { - var environmentObject = JObject.FromObject(environment); + var environmentObject = JObject.FromObject(environment, jsonSerializerOptions); _globalMethod = new GlobalMethod { diff --git a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs index 78ffe0bf579..f5dc5b9bf73 100644 --- a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs +++ b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeExecutor.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using OrchardCore.Environment.Shell; using OrchardCore.Environment.Shell.Scope; using OrchardCore.Modules; @@ -22,6 +23,7 @@ public class RecipeExecutor : IRecipeExecutor private readonly IShellHost _shellHost; private readonly ShellSettings _shellSettings; private readonly IEnumerable _recipeEventHandlers; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly ILogger _logger; private readonly Dictionary> _methodProviders = []; @@ -30,11 +32,13 @@ public RecipeExecutor( IShellHost shellHost, ShellSettings shellSettings, IEnumerable recipeEventHandlers, + IOptions jsonSerializerOptions, ILogger logger) { _shellHost = shellHost; _shellSettings = shellSettings; _recipeEventHandlers = recipeEventHandlers; + _jsonSerializerOptions = jsonSerializerOptions.Value; _logger = logger; } @@ -47,7 +51,7 @@ public async Task ExecuteAsync(string executionId, RecipeDescriptor reci var methodProviders = new List(); _methodProviders.Add(executionId, methodProviders); - methodProviders.Add(new ParametersMethodProvider(environment)); + methodProviders.Add(new ParametersMethodProvider(environment, _jsonSerializerOptions)); methodProviders.Add(new ConfigurationMethodProvider(_shellSettings.ShellConfiguration)); var result = new RecipeResult { ExecutionId = executionId }; diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchIndexDeploymentSource.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchIndexDeploymentSource.cs index 0882725715b..046ebdd20df 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchIndexDeploymentSource.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchIndexDeploymentSource.cs @@ -1,16 +1,19 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Search.AzureAI.Models; using OrchardCore.Search.AzureAI.Services; namespace OrchardCore.Search.AzureAI.Deployment; -public class AzureAISearchIndexDeploymentSource(AzureAISearchIndexSettingsService indexSettingsService) : IDeploymentSource +public class AzureAISearchIndexDeploymentSource(AzureAISearchIndexSettingsService indexSettingsService, IOptions jsonSerializerOptions) : IDeploymentSource { private readonly AzureAISearchIndexSettingsService _indexSettingsService = indexSettingsService; + private readonly JsonSerializerOptions _jsonSerializerOptions = jsonSerializerOptions.Value; public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) { @@ -33,7 +36,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan { index.IndexName, index }, }; - data.Add(JObject.FromObject(indexSettingsDict)); + data.Add(JObject.FromObject(indexSettingsDict, _jsonSerializerOptions)); } } diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs index 14f24ef9ccc..cb7f7b6b1f6 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs @@ -1,14 +1,17 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Search.AzureAI.Models; using OrchardCore.Settings; namespace OrchardCore.Search.AzureAI.Deployment; -public class AzureAISearchSettingsDeploymentSource(ISiteService siteService) : IDeploymentSource +public class AzureAISearchSettingsDeploymentSource(ISiteService siteService, IOptions jsonSerializerOptions) : IDeploymentSource { private readonly ISiteService _siteService = siteService; + private readonly JsonSerializerOptions _jsonSerializerOptions = jsonSerializerOptions.Value; public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) { @@ -26,7 +29,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "Settings", - [nameof(AzureAISearchSettings)] = JObject.FromObject(settings), + [nameof(AzureAISearchSettings)] = JObject.FromObject(settings, _jsonSerializerOptions), }); } } diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Deployment/ElasticIndexDeploymentSource.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Deployment/ElasticIndexDeploymentSource.cs index 44e5493c995..f97769a6fa0 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Deployment/ElasticIndexDeploymentSource.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Deployment/ElasticIndexDeploymentSource.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Search.Elasticsearch.Core.Models; using OrchardCore.Search.Elasticsearch.Core.Services; @@ -11,10 +13,14 @@ namespace OrchardCore.Search.Elasticsearch.Core.Deployment public class ElasticIndexDeploymentSource : IDeploymentSource { private readonly ElasticIndexSettingsService _elasticIndexSettingsService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ElasticIndexDeploymentSource(ElasticIndexSettingsService elasticIndexSettingsService) + public ElasticIndexDeploymentSource( + ElasticIndexSettingsService elasticIndexSettingsService, + IOptions jsonSerializerOptions) { _elasticIndexSettingsService = elasticIndexSettingsService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -40,7 +46,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan { index.IndexName, index }, }; - data.Add(JObject.FromObject(indexSettingsDict)); + data.Add(JObject.FromObject(indexSettingsDict, _jsonSerializerOptions)); } } diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Deployment/ElasticSettingsDeploymentSource.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Deployment/ElasticSettingsDeploymentSource.cs index ecbe1d9e763..f9053c22ee3 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Deployment/ElasticSettingsDeploymentSource.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Deployment/ElasticSettingsDeploymentSource.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Deployment; using OrchardCore.Search.Elasticsearch.Core.Services; @@ -8,10 +10,14 @@ namespace OrchardCore.Search.Elasticsearch.Core.Deployment public class ElasticSettingsDeploymentSource : IDeploymentSource { private readonly ElasticIndexingService _elasticIndexingService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ElasticSettingsDeploymentSource(ElasticIndexingService elasticIndexingService) + public ElasticSettingsDeploymentSource( + ElasticIndexingService elasticIndexingService, + IOptions jsonSerializerOptions) { _elasticIndexingService = elasticIndexingService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -29,7 +35,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JsonObject { ["name"] = "Settings", - ["ElasticSettings"] = JObject.FromObject(elasticSettings), + ["ElasticSettings"] = JObject.FromObject(elasticSettings, _jsonSerializerOptions), }); } } From 7e50b3424912775c5653ecbe4b48bd09b8881686 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Fri, 16 Feb 2024 09:39:58 -0800 Subject: [PATCH 04/11] Use JsonSerializerOptions all over the place --- .../Recipes/AdminMenuStep.cs | 2 +- .../Handlers/AutoroutePartHandler.cs | 10 +++-- .../OrchardCore.Autoroute/Migrations.cs | 10 ++++- .../OrchardCore.Autoroute/Startup.cs | 5 ++- .../OrchardCore.ContentFields/Migrations.cs | 37 +++++++++------- .../Settings/BooleanFieldSettingsDriver.cs | 11 ++++- .../Settings/DateFieldSettingsDriver.cs | 11 ++++- .../Settings/DateTimeFieldSettingsDriver.cs | 11 ++++- .../Settings/LinkFieldSettingsDriver.cs | 11 ++++- ...tionSetContentPickerFieldSettingsDriver.cs | 11 ++++- .../Settings/NumericFieldSettingsDriver.cs | 11 ++++- .../Settings/TextFieldSettingsDriver.cs | 11 ++++- .../Settings/TimeFieldSettingsDriver.cs | 11 ++++- .../Settings/YoutubeFieldSettingsDriver.cs | 11 ++++- .../RecipeSteps/ContentDefinitionStep.cs | 10 ++++- .../DeleteContentDefinitionStep.cs | 10 ++++- .../ReplaceContentDefinitionStep.cs | 10 ++++- .../Recipes/LuceneRecipeEventHandler.cs | 2 +- .../Controllers/ItemController.cs | 7 +++- .../Liquid/BuildDisplayFilter.cs | 10 ++++- .../Liquid/FullTextFilter.cs | 13 ++++-- .../Recipes/ContentStep.cs | 13 +++++- .../Workflows/Activities/ContentActivity.cs | 13 ++++-- .../Activities/ContentCreatedEvent.cs | 9 +++- .../Activities/ContentDeletedEvent.cs | 9 +++- .../Activities/ContentDraftSavedEvent.cs | 9 +++- .../Workflows/Activities/ContentEvent.cs | 9 +++- .../Activities/ContentPublishedEvent.cs | 9 +++- .../Workflows/Activities/ContentTask.cs | 10 ++++- .../Activities/ContentUnpublishedEvent.cs | 9 +++- .../Activities/ContentUpdatedEvent.cs | 9 +++- .../Activities/ContentVersionedEvent.cs | 8 +++- .../Workflows/Activities/CreateContentTask.cs | 4 +- .../Workflows/Activities/DeleteContentTask.cs | 8 +++- .../Activities/PublishContentTask.cs | 9 +++- .../Activities/RetrieveContentTask.cs | 9 +++- .../Activities/UnpublishContentTask.cs | 9 +++- .../Workflows/Activities/UpdateContentTask.cs | 4 +- .../Services/CustomSettingsService.cs | 7 +++- .../Recipes/DeploymentPlansRecipeStep.cs | 9 +++- .../Recipes/FacebookLoginSettingsStep.cs | 10 ++++- .../Recipes/FacebookSettingsStep.cs | 10 ++++- .../Recipes/Executors/FeatureStep.cs | 10 ++++- .../OrchardCore.Flows/Migrations.cs | 10 ++++- .../GithubAuthenticationSettingsStep.cs | 10 ++++- .../OrchardCore.Lists/Migrations.cs | 10 ++++- .../OrchardCore.Markdown/Migrations.cs | 10 ++++- .../OrchardCore.Media/Migrations.cs | 11 ++++- .../Recipes/MediaProfileStep.cs | 10 ++++- .../OrchardCore.Media/Recipes/MediaStep.cs | 6 ++- .../Controllers/AdminController.cs | 2 +- .../Recipes/AzureADSettingsStep.cs | 10 ++++- .../Recipes/MicrosoftAccountSettingsStep.cs | 10 ++++- .../Recipes/OpenIdApplicationStep.cs | 10 ++++- .../Recipes/OpenIdClientSettingsStep.cs | 10 ++++- .../Recipes/OpenIdScopeStep.cs | 10 ++++- .../Recipes/OpenIdServerSettingsStep.cs | 14 +++++-- .../Recipes/OpenIdValidationSettingsStep.cs | 14 +++++-- .../Services/OpenIdServerService.cs | 2 +- .../Services/OpenIdValidationService.cs | 2 +- .../Recipes/PlacementStep.cs | 10 ++++- .../OrchardCore.Queries/Recipes/QueryStep.cs | 9 +++- .../RecipeSteps/CommandStep.cs | 7 +++- .../RecipeSteps/RecipesStep.cs | 10 ++++- .../OrchardCore.Roles/Recipes/RolesStep.cs | 12 +++++- ...tPickerFieldElasticEditorSettingsDriver.cs | 10 ++++- .../Recipes/LuceneIndexRebuildStep.cs | 11 ++++- .../Recipes/LuceneIndexResetStep.cs | 11 ++++- .../Recipes/LuceneIndexStep.cs | 7 +++- ...ntPickerFieldLuceneEditorSettingsDriver.cs | 10 ++++- .../Recipes/SettingsStep.cs | 10 ++++- .../Recipes/ShortcodeTemplateStep.cs | 10 ++++- .../Recipes/SitemapsStep.cs | 12 ++++-- .../Drivers/GeoPointFieldSettingsDriver.cs | 11 ++++- .../Controllers/AdminController.cs | 8 ++-- .../TaxonomyContentsAdminListDisplayDriver.cs | 10 ++++- .../Drivers/TaxonomyFieldDisplayDriver.cs | 7 +++- .../Drivers/TaxonomyFieldDriverHelper.cs | 7 ++-- .../Drivers/TaxonomyFieldTagsDisplayDriver.cs | 14 +++++-- .../Drivers/TaxonomyPartDisplayDriver.cs | 2 +- .../GraphQL/TaxonomyFieldQueryObjectType.cs | 7 +++- .../Helper/TaxonomyOrchardHelperExtensions.cs | 23 +++++----- .../Indexing/TaxonomyFieldIndexHandler.cs | 10 ++++- .../Indexing/TaxonomyIndex.cs | 10 ++++- .../Liquid/InheritedTermsFilter.cs | 10 ++++- .../Liquid/TaxonomyTermsFilter.cs | 11 ++++- .../OrchardCore.Taxonomies/Migrations.cs | 10 ++++- .../Settings/TaxonomyFieldSettingsDriver.cs | 11 ++++- .../TaxonomyFieldTagsEditorSettingsDriver.cs | 14 +++++-- .../OrchardCore.Taxonomies/TermShapes.cs | 21 +++++++--- .../Views/Content.TermAdmin.cshtml | 42 ++++++++++--------- .../Views/TaxonomyField.cshtml | 5 ++- .../Recipes/AdminTemplateStep.cs | 10 ++++- .../Recipes/TemplateStep.cs | 10 ++++- .../Recipes/FeatureProfilesStep.cs | 10 ++++- .../OrchardCore.Themes/Recipes/ThemesStep.cs | 7 +++- .../Recipes/TwitterSettingsStep.cs | 10 ++++- .../CustomUserSettingsDisplayDriver.cs | 2 +- .../Recipes/CustomUserSettingsStep.cs | 10 ++++- .../OrchardCore.Users/Recipes/UsersStep.cs | 7 +++- .../Services/CustomUserSettingsService.cs | 9 +++- .../Recipes/WorkflowTypeStep.cs | 9 +++- .../Services/WorkflowManager.cs | 2 +- .../Drivers/UserTaskEventContentDriver.cs | 10 ++++- .../Indexes/AutoroutePartIndex.cs | 10 ++++- .../ContentDefinitionManagerExtensions.cs | 21 ++++++---- .../IContentManager.cs | 11 +++-- .../Records/Migrations.cs | 17 +++++--- .../Documents/DocumentEntityManagerOfT.cs | 7 +++- .../VolatileDocumentEntityManager.cs | 8 +++- .../Recipes/AzureAISearchIndexRebuildStep.cs | 11 ++++- .../Recipes/AzureAISearchIndexResetStep.cs | 11 ++++- .../Recipes/AzureAISearchIndexSettingsStep.cs | 34 ++++++++++----- .../Recipes/ElasticIndexRebuildStep.cs | 11 ++++- .../Recipes/ElasticIndexResetStep.cs | 11 ++++- .../Recipes/ElasticIndexStep.cs | 9 +++- .../Services/ElasticIndexingService.cs | 10 +++-- .../Services/IWorkflowManager.cs | 5 ++- .../OrchardCore/Shell/ShellSettingsManager.cs | 7 +++- .../ContentStepLuceneQueryTests.cs | 2 +- .../OpenIdApplicationStepTests.cs | 9 +++- .../OpenIdScopeStepTests.cs | 9 +++- .../OpenIdServerDeploymentSourceTests.cs | 4 +- .../Recipes/RecipeExecutorTests.cs | 6 ++- .../Workflows/WorkflowManagerTests.cs | 4 ++ 125 files changed, 977 insertions(+), 270 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs index 10ce21a711f..4e8d24bbc57 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs @@ -33,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_serializationOptions); foreach (var token in model.Data.Cast()) { diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs index 833546fdd66..d786e3d816e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Settings; using System.Threading.Tasks; @@ -36,6 +37,7 @@ public class AutoroutePartHandler : ContentPartHandler private readonly ISiteService _siteService; private readonly ITagCache _tagCache; private readonly ISession _session; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IServiceProvider _serviceProvider; protected readonly IStringLocalizer S; @@ -49,6 +51,7 @@ public AutoroutePartHandler( ISiteService siteService, ITagCache tagCache, ISession session, + IOptions jsonSerializerOptions, IServiceProvider serviceProvider, IStringLocalizer stringLocalizer) { @@ -59,6 +62,7 @@ public AutoroutePartHandler( _siteService = siteService; _tagCache = tagCache; _session = session; + _jsonSerializerOptions = jsonSerializerOptions.Value; _serviceProvider = serviceProvider; S = stringLocalizer; } @@ -202,7 +206,7 @@ private async Task CheckContainedHomeRouteAsync(string containerContentItemId, C foreach (var jItem in jItems.Cast()) { - var contentItem = jItem.ToObject(); + var contentItem = jItem.ToObject(_jsonSerializerOptions); var handlerAspect = await _contentManager.PopulateAspectAsync(contentItem); if (!handlerAspect.Disabled) @@ -250,7 +254,7 @@ private async Task PopulateContainedContentItemRoutesAsync(List foreach (var jItem in jItems.Cast()) { - var contentItem = jItem.ToObject(); + var contentItem = jItem.ToObject(_jsonSerializerOptions); var handlerAspect = await _contentManager.PopulateAspectAsync(contentItem); if (!handlerAspect.Disabled) @@ -282,7 +286,7 @@ private async Task ValidateContainedContentItemRoutesAsync(List foreach (var jItem in jItems.Cast()) { - var contentItem = jItem.ToObject(); + var contentItem = jItem.ToObject(_jsonSerializerOptions); var containedAutoroutePart = contentItem.As(); // This is only relevant if the content items have an autoroute part as we adjust the part value as required to guarantee a unique route. diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs index 7db23059adf..d3c7d4d9099 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Migrations.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Autoroute.Core.Indexes; using OrchardCore.Autoroute.Models; using OrchardCore.ContentManagement.Metadata; @@ -11,10 +13,14 @@ namespace OrchardCore.Autoroute public class Migrations : DataMigration { private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public Migrations(IContentDefinitionManager contentDefinitionManager) + public Migrations( + IContentDefinitionManager contentDefinitionManager, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task CreateAsync() @@ -40,7 +46,7 @@ await SchemaBuilder.CreateMapIndexTableAsync(table => table // This code can be removed in a later version. public async Task UpdateFrom1Async() { - await _contentDefinitionManager.MigratePartSettingsAsync(); + await _contentDefinitionManager.MigratePartSettingsAsync(_jsonSerializerOptions); return 2; } diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs index 13573cc11ef..67e03226108 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Startup.cs @@ -1,9 +1,11 @@ using System; +using System.Text.Json; using Fluid; using Fluid.Values; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OrchardCore.Autoroute.Core.Indexes; using OrchardCore.Autoroute.Core.Services; using OrchardCore.Autoroute.Drivers; @@ -59,7 +61,8 @@ public override void ConfigureServices(IServiceCollection services) if (found) { - return FluidValue.Create(await contentManager.GetAsync(entry.ContentItemId, entry.JsonPath), context.Options); + var options = context.Services.GetService>(); + return FluidValue.Create(await contentManager.GetAsync(entry.ContentItemId, entry.JsonPath, options.Value), context.Options); } return NilValue.Instance; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Migrations.cs index 4131435aa4e..ddf54b3145d 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Migrations.cs @@ -1,5 +1,7 @@ using System.Linq; +using System.Text.Json; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentFields.Settings; using OrchardCore.ContentManagement.Metadata; @@ -13,11 +15,16 @@ public class Migrations : DataMigration { private readonly IContentDefinitionManager _contentDefinitionManager; private readonly ShellDescriptor _shellDescriptor; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public Migrations(IContentDefinitionManager contentDefinitionManager, ShellDescriptor shellDescriptor) + public Migrations( + IContentDefinitionManager contentDefinitionManager, + ShellDescriptor shellDescriptor, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; _shellDescriptor = shellDescriptor; + _jsonSerializerOptions = jsonSerializerOptions.Value; } // New installations don't need to be upgraded, but because there is no initial migration record, @@ -37,42 +44,42 @@ public async Task CreateAsync() private async Task UpgradeAsync() { // Boolean field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Content picker field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Date field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Date time field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Html field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Link field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Localization set content picker field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // MultiText field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Numeric field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Text field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); - await _contentDefinitionManager.MigrateFieldSettingsAsync(); - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Time field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // YouTube field - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); // Keep in sync the upgrade process. await UpdateFrom1Async(); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/BooleanFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/BooleanFieldSettingsDriver.cs index 9f3759b332d..b54f008c20f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/BooleanFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/BooleanFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -9,11 +11,18 @@ namespace OrchardCore.ContentFields.Settings { public class BooleanFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public BooleanFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("BooleanFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.Label = settings.Label; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateFieldSettingsDriver.cs index c332cd76ff6..789c85036ac 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -9,11 +11,18 @@ namespace OrchardCore.ContentFields.Settings { public class DateFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public DateFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("DateFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.Required = settings.Required; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateTimeFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateTimeFieldSettingsDriver.cs index 4041c83874f..f56ceb86465 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateTimeFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateTimeFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -9,11 +11,18 @@ namespace OrchardCore.ContentFields.Settings { public class DateTimeFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public DateTimeFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("DateTimeFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.Required = settings.Required; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LinkFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LinkFieldSettingsDriver.cs index 6d61f64e832..88e0341dbd4 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LinkFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LinkFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -9,11 +11,18 @@ namespace OrchardCore.ContentFields.Settings { public class LinkFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public LinkFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("LinkFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.HintLinkText = settings.HintLinkText; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LocalizationSetContentPickerFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LocalizationSetContentPickerFieldSettingsDriver.cs index fb2a4018eb0..cf0a38d9336 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LocalizationSetContentPickerFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LocalizationSetContentPickerFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -11,11 +13,18 @@ namespace OrchardCore.ContentFields.Settings [RequireFeatures("OrchardCore.ContentLocalization")] public class LocalizationSetContentPickerFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public LocalizationSetContentPickerFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("LocalizationSetContentPickerFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.Required = settings.Required; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/NumericFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/NumericFieldSettingsDriver.cs index ddf2c171f48..05d41f26d68 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/NumericFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/NumericFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -9,11 +11,18 @@ namespace OrchardCore.ContentFields.Settings { public class NumericFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public NumericFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("NumericFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.Required = settings.Required; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldSettingsDriver.cs index ed5eb8d2c5e..95774851ea5 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -9,11 +11,18 @@ namespace OrchardCore.ContentFields.Settings { public class TextFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public TextFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("TextFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.Required = settings.Required; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TimeFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TimeFieldSettingsDriver.cs index dfa539ab27b..b5bf50a1596 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TimeFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TimeFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -9,11 +11,18 @@ namespace OrchardCore.ContentFields.Settings { public class TimeFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public TimeFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("TimeFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.Required = settings.Required; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/YoutubeFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/YoutubeFieldSettingsDriver.cs index 436395fe7e6..3634ab37221 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/YoutubeFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/YoutubeFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -9,11 +11,18 @@ namespace OrchardCore.ContentFields.Settings { public class YoutubeFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public YoutubeFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("YoutubeFieldSetting_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Height = model.Height != default ? model.Height : 315; model.Width = model.Width != default ? model.Width : 560; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs index 73caa66a5c5..4c1de52dd26 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentManagement.Metadata.Records; @@ -15,10 +17,14 @@ namespace OrchardCore.ContentTypes.RecipeSteps public class ContentDefinitionStep : IRecipeStepHandler { private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ContentDefinitionStep(IContentDefinitionManager contentDefinitionManager) + public ContentDefinitionStep( + IContentDefinitionManager contentDefinitionManager, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -28,7 +34,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var step = context.Step.ToObject(); + var step = context.Step.ToObject(_jsonSerializerOptions); foreach (var contentType in step.ContentTypes) { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs index 2e243eb2e81..49173c34341 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -13,10 +15,14 @@ namespace OrchardCore.ContentTypes.RecipeSteps public class DeleteContentDefinitionStep : IRecipeStepHandler { private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public DeleteContentDefinitionStep(IContentDefinitionManager contentDefinitionManager) + public DeleteContentDefinitionStep( + IContentDefinitionManager contentDefinitionManager, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -26,7 +32,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var step = context.Step.ToObject(); + var step = context.Step.ToObject(_jsonSerializerOptions); foreach (var contentType in step.ContentTypes) { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs index 6822f856922..49d939c319f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Records; using OrchardCore.Recipes.Models; @@ -14,10 +16,14 @@ namespace OrchardCore.ContentTypes.RecipeSteps public class ReplaceContentDefinitionStep : IRecipeStepHandler { private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ReplaceContentDefinitionStep(IContentDefinitionManager contentDefinitionManager) + public ReplaceContentDefinitionStep( + IContentDefinitionManager contentDefinitionManager, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -27,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var step = context.Step.ToObject(); + var step = context.Step.ToObject(_jsonSerializerOptions); // Delete existing parts first, as deleting them later will clear any imported content types using them. foreach (var contentPart in step.ContentParts) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs index 515fd44e107..65a728fc659 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs @@ -34,7 +34,7 @@ public Task RecipeStepExecutingAsync(RecipeExecutionContext context) { if (context.Name == "ReplaceContentDefinition" || context.Name == "ContentDefinition") { - var step = context.Step.ToObject(); + var step = context.Step.ToObject(_jsonSerializerOptions); foreach (var contentType in step.ContentTypes) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ItemController.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ItemController.cs index 5f6c9cee5d8..bf84cc1512c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ItemController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ItemController.cs @@ -1,6 +1,8 @@ +using System.Text.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; using OrchardCore.DisplayManagement.ModelBinding; @@ -11,24 +13,27 @@ public class ItemController : Controller { private readonly IContentManager _contentManager; private readonly IContentItemDisplayManager _contentItemDisplayManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IAuthorizationService _authorizationService; private readonly IUpdateModelAccessor _updateModelAccessor; public ItemController( IContentManager contentManager, IContentItemDisplayManager contentItemDisplayManager, + IOptions jsonSerializerOptions, IAuthorizationService authorizationService, IUpdateModelAccessor updateModelAccessor) { _authorizationService = authorizationService; _contentItemDisplayManager = contentItemDisplayManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; _contentManager = contentManager; _updateModelAccessor = updateModelAccessor; } public async Task Display(string contentItemId, string jsonPath) { - var contentItem = await _contentManager.GetAsync(contentItemId, jsonPath); + var contentItem = await _contentManager.GetAsync(contentItemId, jsonPath, _jsonSerializerOptions); if (contentItem == null) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/BuildDisplayFilter.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/BuildDisplayFilter.cs index 2185293499a..0c99c17d2d1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/BuildDisplayFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/BuildDisplayFilter.cs @@ -1,8 +1,10 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Fluid; using Fluid.Values; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; using OrchardCore.DisplayManagement; @@ -16,14 +18,18 @@ public class BuildDisplayFilter : ILiquidFilter private const int DefaultMaxContentItemRecursions = 20; private readonly IContentItemRecursionHelper _buildDisplayRecursionHelper; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IContentItemDisplayManager _contentItemDisplayManager; private readonly IUpdateModelAccessor _updateModelAccessor; - public BuildDisplayFilter(IContentItemRecursionHelper buildDisplayRecursionHelper, + public BuildDisplayFilter( + IContentItemRecursionHelper buildDisplayRecursionHelper, + IOptions jsonSerializerOptions, IContentItemDisplayManager contentItemDisplayManager, IUpdateModelAccessor updateModelAccessor) { _buildDisplayRecursionHelper = buildDisplayRecursionHelper; + _jsonSerializerOptions = jsonSerializerOptions.Value; _contentItemDisplayManager = contentItemDisplayManager; _updateModelAccessor = updateModelAccessor; } @@ -43,7 +49,7 @@ static async ValueTask Awaited(Task task, TemplateOptions op if (obj is JsonObject jObject) { - contentItem = jObject.ToObject(); + contentItem = jObject.ToObject(_jsonSerializerOptions); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/FullTextFilter.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/FullTextFilter.cs index adea189a572..1aad7541535 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/FullTextFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/FullTextFilter.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Fluid; using Fluid.Values; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Models; using OrchardCore.Liquid; @@ -14,11 +16,16 @@ public class FullTextFilter : ILiquidFilter { private readonly IContentManager _contentManager; private readonly IContentItemRecursionHelper _fullTextRecursionHelper; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public FullTextFilter(IContentManager contentManager, IContentItemRecursionHelper fullTextRecursionHelper) + public FullTextFilter( + IContentManager contentManager, + IContentItemRecursionHelper fullTextRecursionHelper, + IOptions jsonSerializerOptions) { _contentManager = contentManager; _fullTextRecursionHelper = fullTextRecursionHelper; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async ValueTask ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx) @@ -69,7 +76,7 @@ public async ValueTask ProcessAsync(FluidValue input, FilterArgument } } - private static ContentItem GetContentItem(FluidValue input) + private ContentItem GetContentItem(FluidValue input) { var obj = input.ToObjectValue(); @@ -79,7 +86,7 @@ private static ContentItem GetContentItem(FluidValue input) if (obj is JsonObject jObject) { - contentItem = jObject.ToObject(); + contentItem = jObject.ToObject(_jsonSerializerOptions); // If input is a 'JObject' but which not represents a 'ContentItem', // a 'ContentItem' is still created but with some null properties. if (contentItem?.ContentItemId == null) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs index f59787d0cd6..1be8c31ec2c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs @@ -1,7 +1,9 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Environment.Shell.Scope; using OrchardCore.Recipes.Models; @@ -14,6 +16,13 @@ namespace OrchardCore.Contents.Recipes /// public class ContentStep : IRecipeStepHandler { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public ContentStep(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public Task ExecuteAsync(RecipeExecutionContext context) { if (!string.Equals(context.Name, "Content", StringComparison.OrdinalIgnoreCase)) @@ -21,8 +30,8 @@ public Task ExecuteAsync(RecipeExecutionContext context) return Task.CompletedTask; } - var model = context.Step.ToObject(); - var contentItems = model.Data.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); + var contentItems = model.Data.ToObject(_jsonSerializerOptions); // If the shell is activated there is no migration in progress. if (ShellScope.Context.IsActivated) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs index ce7900fa5ce..4801153adb9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Workflows; using OrchardCore.Workflows.Abstractions.Models; @@ -16,15 +17,19 @@ namespace OrchardCore.Contents.Workflows.Activities { public abstract class ContentActivity : Activity { + private readonly JsonSerializerOptions _jsonSerializerOptions; + protected readonly IStringLocalizer S; protected ContentActivity( IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, IStringLocalizer localizer) { ContentManager = contentManager; ScriptEvaluator = scriptEvaluator; + _jsonSerializerOptions = jsonSerializerOptions.Value; S = localizer; } @@ -78,7 +83,7 @@ public override async Task OnWorkflowRestartingAsync(WorkflowExecutionContext wo if (workflowContext.Input.TryGetValue(ContentEventConstants.ContentEventInputKey, out var contentEvent)) { - var contentEventContext = ((JsonObject)contentEvent).ToObject(); + var contentEventContext = ((JsonObject)contentEvent).ToObject(_jsonSerializerOptions); if (contentEventContext?.ContentItemVersionId != null) { @@ -92,7 +97,7 @@ public override async Task OnWorkflowRestartingAsync(WorkflowExecutionContext wo if (contentItem == null && workflowContext.Input.TryGetValue(ContentEventConstants.ContentItemInputKey, out var contentItemEvent)) { - var item = ((JsonObject)contentItemEvent).ToObject(); + var item = ((JsonObject)contentItemEvent).ToObject(_jsonSerializerOptions); if (item?.ContentItemId != null) { @@ -127,8 +132,8 @@ protected virtual async Task GetContentAsync(WorkflowExecutionContext else { // Try to map the result to a content item. - var json = JConvert.SerializeObject(result); - content = JConvert.DeserializeObject(json); + var json = JConvert.SerializeObject(result, _jsonSerializerOptions); + content = JConvert.DeserializeObject(json, _jsonSerializerOptions); } } else diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentCreatedEvent.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentCreatedEvent.cs index 289783fe5a2..23afe4eeabf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentCreatedEvent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentCreatedEvent.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Services; @@ -6,7 +8,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public class ContentCreatedEvent : ContentEvent { - public ContentCreatedEvent(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public ContentCreatedEvent( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, localizer, jsonSerializerOptions) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentDeletedEvent.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentDeletedEvent.cs index fd3e6662b7c..15e04d8c189 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentDeletedEvent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentDeletedEvent.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Services; @@ -6,7 +8,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public class ContentDeletedEvent : ContentEvent { - public ContentDeletedEvent(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public ContentDeletedEvent( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, localizer, jsonSerializerOptions) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentDraftSavedEvent.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentDraftSavedEvent.cs index 21b93d631e6..16401c578a1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentDraftSavedEvent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentDraftSavedEvent.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Services; @@ -6,7 +8,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public class ContentDraftSavedEvent : ContentEvent { - public ContentDraftSavedEvent(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public ContentDraftSavedEvent( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, localizer, jsonSerializerOptions) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentEvent.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentEvent.cs index d2e3c401a7d..1cbdfec792a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentEvent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentEvent.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Activities; using OrchardCore.Workflows.Models; @@ -11,7 +13,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public abstract class ContentEvent : ContentActivity, IEvent { - protected ContentEvent(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + protected ContentEvent( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IStringLocalizer localizer, + IOptions jsonSerializerOptions) + : base(contentManager, scriptEvaluator, jsonSerializerOptions, localizer) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentPublishedEvent.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentPublishedEvent.cs index 9e37381ed4f..910c5ba40fe 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentPublishedEvent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentPublishedEvent.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Services; @@ -6,7 +8,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public class ContentPublishedEvent : ContentEvent { - public ContentPublishedEvent(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public ContentPublishedEvent( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, localizer, jsonSerializerOptions) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentTask.cs index b261683acab..5f907b52033 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentTask.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Activities; using OrchardCore.Workflows.Services; @@ -7,8 +9,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public abstract class ContentTask : ContentActivity, ITask { - protected ContentTask(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) - : base(contentManager, scriptEvaluator, localizer) + protected ContentTask( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, jsonSerializerOptions, localizer) { } } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentUnpublishedEvent.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentUnpublishedEvent.cs index 64938986b15..1188c4d0a66 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentUnpublishedEvent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentUnpublishedEvent.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Services; @@ -6,7 +8,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public class ContentUnpublishedEvent : ContentEvent { - public ContentUnpublishedEvent(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public ContentUnpublishedEvent( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, localizer, jsonSerializerOptions) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentUpdatedEvent.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentUpdatedEvent.cs index 8ecc1238f3d..116196cdc03 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentUpdatedEvent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentUpdatedEvent.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Services; @@ -6,7 +8,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public class ContentUpdatedEvent : ContentEvent { - public ContentUpdatedEvent(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public ContentUpdatedEvent( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, localizer, jsonSerializerOptions) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentVersionedEvent.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentVersionedEvent.cs index 51322519090..915a34e8693 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentVersionedEvent.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentVersionedEvent.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Services; @@ -6,7 +8,11 @@ namespace OrchardCore.Contents.Workflows.Activities { public class ContentVersionedEvent : ContentEvent { - public ContentVersionedEvent(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public ContentVersionedEvent(IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, localizer, jsonSerializerOptions) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs index 27c2ede4d60..b752f0f8141 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs @@ -5,6 +5,7 @@ using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Workflows; using OrchardCore.Workflows.Abstractions.Models; @@ -24,8 +25,9 @@ public CreateContentTask( IWorkflowExpressionEvaluator expressionEvaluator, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer, + IOptions jsonSerializerOptions, JavaScriptEncoder javaScriptEncoder) - : base(contentManager, scriptEvaluator, localizer) + : base(contentManager, scriptEvaluator, jsonSerializerOptions, localizer) { _expressionEvaluator = expressionEvaluator; _javaScriptEncoder = javaScriptEncoder; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/DeleteContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/DeleteContentTask.cs index 7022ebc6185..65884f318ca 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/DeleteContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/DeleteContentTask.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Abstractions.Models; using OrchardCore.Workflows.Activities; @@ -12,7 +14,11 @@ namespace OrchardCore.Contents.Workflows.Activities { public class DeleteContentTask : ContentTask { - public DeleteContentTask(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public DeleteContentTask(IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, jsonSerializerOptions, localizer) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/PublishContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/PublishContentTask.cs index f6919242a23..61743a3b14c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/PublishContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/PublishContentTask.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Abstractions.Models; using OrchardCore.Workflows.Activities; @@ -12,7 +14,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public class PublishContentTask : ContentTask { - public PublishContentTask(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public PublishContentTask( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, jsonSerializerOptions, localizer) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs index b5475c5debb..88a13cded1c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/RetrieveContentTask.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Workflows; using OrchardCore.Workflows.Abstractions.Models; @@ -13,7 +15,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public class RetrieveContentTask : ContentTask { - public RetrieveContentTask(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public RetrieveContentTask( + IContentManager contentManager, + IOptions jsonSerializerOptions, + IWorkflowScriptEvaluator scriptEvaluator, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, jsonSerializerOptions, localizer) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UnpublishContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UnpublishContentTask.cs index af2b8a4a3af..222cb39112b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UnpublishContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UnpublishContentTask.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Abstractions.Models; using OrchardCore.Workflows.Activities; @@ -12,7 +14,12 @@ namespace OrchardCore.Contents.Workflows.Activities { public class UnpublishContentTask : ContentTask { - public UnpublishContentTask(IContentManager contentManager, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer) : base(contentManager, scriptEvaluator, localizer) + public UnpublishContentTask( + IContentManager contentManager, + IWorkflowScriptEvaluator scriptEvaluator, + IOptions jsonSerializerOptions, + IStringLocalizer localizer) + : base(contentManager, scriptEvaluator, jsonSerializerOptions, localizer) { } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs index 77c0061be1b..5c0494a796d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs @@ -6,6 +6,7 @@ using System.Text.Json.Settings; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Workflows; using OrchardCore.DisplayManagement.ModelBinding; @@ -29,8 +30,9 @@ public UpdateContentTask( IWorkflowExpressionEvaluator expressionEvaluator, IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer localizer, + IOptions jsonSerializerOptions, JavaScriptEncoder javaScriptEncoder) - : base(contentManager, scriptEvaluator, localizer) + : base(contentManager, scriptEvaluator, jsonSerializerOptions, localizer) { _updateModelAccessor = updateModelAccessor; _expressionEvaluator = expressionEvaluator; diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsService.cs index d7c4d4b9186..ec4f63340a8 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/Services/CustomSettingsService.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; @@ -18,6 +20,7 @@ public class CustomSettingsService private readonly IContentManager _contentManager; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IAuthorizationService _authorizationService; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IContentDefinitionManager _contentDefinitionManager; private readonly Lazy>> _settingsTypes; @@ -26,12 +29,14 @@ public CustomSettingsService( IContentManager contentManager, IHttpContextAccessor httpContextAccessor, IAuthorizationService authorizationService, + IOptions jsonSerializerOptions, IContentDefinitionManager contentDefinitionManager) { _siteService = siteService; _contentManager = contentManager; _httpContextAccessor = httpContextAccessor; _authorizationService = authorizationService; + _jsonSerializerOptions = jsonSerializerOptions.Value; _contentDefinitionManager = contentDefinitionManager; _settingsTypes = new Lazy>>(async () => await GetContentTypeAsync()); } @@ -114,7 +119,7 @@ public async Task GetSettingsAsync(ISite site, ContentTypeDefinitio if (site.Properties.TryGetPropertyValue(settingsType.Name, out property)) { - var existing = property.ToObject(); + var existing = property.ToObject(_jsonSerializerOptions); // Create a new item to take into account the current type definition. contentItem = await _contentManager.NewAsync(existing.ContentType); diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs b/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs index 22af8f5010b..f60579b6b86 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment/Recipes/DeploymentPlansRecipeStep.cs @@ -1,9 +1,11 @@ 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.DependencyInjection; +using Microsoft.Extensions.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -15,13 +17,16 @@ namespace OrchardCore.Deployment.Recipes public class DeploymentPlansRecipeStep : IRecipeStepHandler { private readonly IServiceProvider _serviceProvider; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly IDeploymentPlanService _deploymentPlanService; public DeploymentPlansRecipeStep( IServiceProvider serviceProvider, + IOptions jsonSerializerOptions, IDeploymentPlanService deploymentPlanService) { _serviceProvider = serviceProvider; + _jsonSerializerOptions = jsonSerializerOptions.Value; _deploymentPlanService = deploymentPlanService; } @@ -34,7 +39,7 @@ public Task ExecuteAsync(RecipeExecutionContext context) var deploymentStepFactories = _serviceProvider.GetServices().ToDictionary(f => f.Name); - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var unknownTypes = new List(); var deploymentPlans = new List(); @@ -50,7 +55,7 @@ public Task ExecuteAsync(RecipeExecutionContext context) { if (deploymentStepFactories.TryGetValue(step.Type, out var deploymentStepFactory)) { - var deploymentStep = (DeploymentStep)step.Step.ToObject(deploymentStepFactory.Create().GetType()); + var deploymentStep = (DeploymentStep)step.Step.ToObject(deploymentStepFactory.Create().GetType(), _jsonSerializerOptions); deploymentPlan.DeploymentSteps.Add(deploymentStep); } diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Recipes/FacebookLoginSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Recipes/FacebookLoginSettingsStep.cs index 46e45966562..0e4aa5c7860 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Recipes/FacebookLoginSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Recipes/FacebookLoginSettingsStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Facebook.Login.Services; using OrchardCore.Facebook.Login.Settings; using OrchardCore.Recipes.Models; @@ -14,10 +16,14 @@ namespace OrchardCore.Facebook.Login.Recipes public class FacebookLoginSettingsStep : IRecipeStepHandler { private readonly IFacebookLoginService _loginService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public FacebookLoginSettingsStep(IFacebookLoginService loginService) + public FacebookLoginSettingsStep( + IFacebookLoginService loginService, + IOptions jsonSerializerOptions) { _loginService = loginService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -27,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var settings = await _loginService.LoadSettingsAsync(); settings.CallbackPath = model.CallbackPath; diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Recipes/FacebookSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Recipes/FacebookSettingsStep.cs index 4ddaec0e112..ef1ca986f2b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Recipes/FacebookSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Recipes/FacebookSettingsStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Facebook.Services; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -13,10 +15,14 @@ namespace OrchardCore.Facebook.Recipes public class FacebookSettingsStep : IRecipeStepHandler { private readonly IFacebookService _facebookService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public FacebookSettingsStep(IFacebookService facebookService) + public FacebookSettingsStep( + IFacebookService facebookService, + IOptions jsonSerializerOptions) { _facebookService = facebookService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -26,7 +32,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var settings = await _facebookService.GetSettingsAsync(); settings.AppId = model.AppId; diff --git a/src/OrchardCore.Modules/OrchardCore.Features/Recipes/Executors/FeatureStep.cs b/src/OrchardCore.Modules/OrchardCore.Features/Recipes/Executors/FeatureStep.cs index 26a7f701851..a607d5e3342 100644 --- a/src/OrchardCore.Modules/OrchardCore.Features/Recipes/Executors/FeatureStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Features/Recipes/Executors/FeatureStep.cs @@ -1,7 +1,9 @@ using System; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Environment.Shell; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -14,10 +16,14 @@ namespace OrchardCore.Features.Recipes.Executors public class FeatureStep : IRecipeStepHandler { private readonly IShellFeaturesManager _shellFeaturesManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public FeatureStep(IShellFeaturesManager shellFeaturesManager) + public FeatureStep( + IShellFeaturesManager shellFeaturesManager, + IOptions jsonSerializerOptions) { _shellFeaturesManager = shellFeaturesManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -27,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var step = context.Step.ToObject(); + var step = context.Step.ToObject(_jsonSerializerOptions); var features = (await _shellFeaturesManager.GetAvailableFeaturesAsync()); diff --git a/src/OrchardCore.Modules/OrchardCore.Flows/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Flows/Migrations.cs index d0b98cfcf6b..55dd626ae2a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Flows/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Flows/Migrations.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -9,10 +11,14 @@ namespace OrchardCore.Flows public class Migrations : DataMigration { private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public Migrations(IContentDefinitionManager contentDefinitionManager) + public Migrations( + IContentDefinitionManager contentDefinitionManager, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task CreateAsync() @@ -45,7 +51,7 @@ await _contentDefinitionManager.AlterPartDefinitionAsync("BagPart", builder => b // This code can be removed in a later version. public async Task UpdateFrom2Async() { - await _contentDefinitionManager.MigratePartSettingsAsync(); + await _contentDefinitionManager.MigratePartSettingsAsync(_jsonSerializerOptions); return 3; } diff --git a/src/OrchardCore.Modules/OrchardCore.GitHub/Recipes/GithubAuthenticationSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.GitHub/Recipes/GithubAuthenticationSettingsStep.cs index 4ed64ade22f..c727c6b02a5 100644 --- a/src/OrchardCore.Modules/OrchardCore.GitHub/Recipes/GithubAuthenticationSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.GitHub/Recipes/GithubAuthenticationSettingsStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.GitHub.Services; using OrchardCore.GitHub.Settings; using OrchardCore.Recipes.Models; @@ -14,10 +16,14 @@ namespace OrchardCore.GitHub.Recipes public class GitHubAuthenticationSettingsStep : IRecipeStepHandler { private readonly IGitHubAuthenticationService _githubAuthenticationService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public GitHubAuthenticationSettingsStep(IGitHubAuthenticationService githubLoginService) + public GitHubAuthenticationSettingsStep( + IGitHubAuthenticationService githubLoginService, + IOptions jsonSerializerOptions) { _githubAuthenticationService = githubLoginService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -26,7 +32,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) { return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var settings = await _githubAuthenticationService.LoadSettingsAsync(); settings.ClientID = model.ConsumerKey; diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs index 038c58aec7c..c48d1129e0f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -11,10 +13,14 @@ namespace OrchardCore.Lists public class Migrations : DataMigration { private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public Migrations(IContentDefinitionManager contentDefinitionManager) + public Migrations( + IContentDefinitionManager contentDefinitionManager, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task CreateAsync() @@ -55,7 +61,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table // This code can be removed in a later version. public async Task UpdateFrom1Async() { - await _contentDefinitionManager.MigratePartSettingsAsync(); + await _contentDefinitionManager.MigratePartSettingsAsync(_jsonSerializerOptions); return 2; } diff --git a/src/OrchardCore.Modules/OrchardCore.Markdown/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Markdown/Migrations.cs index 66ec22a6e86..00a588b3720 100644 --- a/src/OrchardCore.Modules/OrchardCore.Markdown/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Markdown/Migrations.cs @@ -1,5 +1,7 @@ using System.Linq; +using System.Text.Json; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.Data.Migration; @@ -11,10 +13,14 @@ namespace OrchardCore.Markdown public class Migrations : DataMigration { private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public Migrations(IContentDefinitionManager contentDefinitionManager) + public Migrations( + IContentDefinitionManager contentDefinitionManager, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task CreateAsync() @@ -31,7 +37,7 @@ await _contentDefinitionManager.AlterPartDefinitionAsync("MarkdownBodyPart", bui // This code can be removed in a later version. public async Task UpdateFrom1Async() { - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); return 2; } diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Media/Migrations.cs index bc35f2ceaa2..42b09c2de78 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Migrations.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Data.Migration; using OrchardCore.Environment.Shell; @@ -12,11 +14,16 @@ public class Migrations : DataMigration { private readonly IContentDefinitionManager _contentDefinitionManager; private readonly ShellDescriptor _shellDescriptor; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public Migrations(IContentDefinitionManager contentDefinitionManager, ShellDescriptor shellDescriptor) + public Migrations( + IContentDefinitionManager contentDefinitionManager, + ShellDescriptor shellDescriptor, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; _shellDescriptor = shellDescriptor; + _jsonSerializerOptions = jsonSerializerOptions.Value; } // New installations don't need to be upgraded, but because there is no initial migration record, @@ -35,7 +42,7 @@ public async Task CreateAsync() // Upgrade an existing installation. private async Task UpgradeAsync() { - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaProfileStep.cs b/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaProfileStep.cs index cf0de970f68..cae681fc2c3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaProfileStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaProfileStep.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Media.Models; using OrchardCore.Media.Services; using OrchardCore.Recipes.Models; @@ -15,10 +17,14 @@ namespace OrchardCore.Media.Recipes public class MediaProfileStep : IRecipeStepHandler { private readonly MediaProfilesManager _mediaProfilesManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public MediaProfileStep(MediaProfilesManager mediaProfilesManager) + public MediaProfileStep( + MediaProfilesManager mediaProfilesManager, + IOptions jsonSerializerOptions) { _mediaProfilesManager = mediaProfilesManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -28,7 +34,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); foreach (var mediaProfile in model.MediaProfiles) { diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs b/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs index 786fb7f7ef0..c885d9e549d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Net.Http; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.FileProviders; @@ -19,6 +20,7 @@ namespace OrchardCore.Media.Recipes public class MediaStep : IRecipeStepHandler { private readonly IMediaFileStore _mediaFileStore; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly HashSet _allowedFileExtensions; private readonly ILogger _logger; private static readonly HttpClient _httpClient = new(); @@ -26,9 +28,11 @@ public class MediaStep : IRecipeStepHandler public MediaStep( IMediaFileStore mediaFileStore, IOptions options, + IOptions jsonSerializerOptions, ILogger logger) { _mediaFileStore = mediaFileStore; + _jsonSerializerOptions = jsonSerializerOptions.Value; _allowedFileExtensions = options.Value.AllowedFileExtensions; _logger = logger; } @@ -40,7 +44,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); foreach (var file in model.Files) { diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs index c539a79624f..ebc46019469 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/Controllers/AdminController.cs @@ -218,7 +218,7 @@ public async Task EditPost(string menuContentItemId, string menuI return NotFound(); } - var existing = menuItem.ToObject(); + var existing = menuItem.ToObject(_jsonSerializerOptions); // Create a new item to take into account the current type definition. var contentItem = await _contentManager.NewAsync(existing.ContentType); diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/AzureADSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/AzureADSettingsStep.cs index 30a56777d61..a764627a505 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/AzureADSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/AzureADSettingsStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Microsoft.Authentication.Services; using OrchardCore.Microsoft.Authentication.Settings; using OrchardCore.Recipes.Models; @@ -14,10 +16,14 @@ namespace OrchardCore.Microsoft.Authentication.Recipes public class AzureADSettingsStep : IRecipeStepHandler { private readonly IAzureADService _azureADService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AzureADSettingsStep(IAzureADService azureADService) + public AzureADSettingsStep( + IAzureADService azureADService, + IOptions jsonSerializerOptions) { _azureADService = azureADService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -27,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var settings = await _azureADService.LoadSettingsAsync(); settings.AppId = model.AppId; diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/MicrosoftAccountSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/MicrosoftAccountSettingsStep.cs index 642dce35fed..65226c98a1f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/MicrosoftAccountSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Recipes/MicrosoftAccountSettingsStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Microsoft.Authentication.Services; using OrchardCore.Microsoft.Authentication.Settings; using OrchardCore.Recipes.Models; @@ -14,10 +16,14 @@ namespace OrchardCore.Microsoft.Authentication.Recipes public class MicrosoftAccountSettingsStep : IRecipeStepHandler { private readonly IMicrosoftAccountService _microsoftAccountService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public MicrosoftAccountSettingsStep(IMicrosoftAccountService microsoftAccountService) + public MicrosoftAccountSettingsStep( + IMicrosoftAccountService microsoftAccountService, + IOptions jsonSerializerOptions) { _microsoftAccountService = microsoftAccountService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -27,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var settings = await _microsoftAccountService.LoadSettingsAsync(); settings.AppId = model.AppId; diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdApplicationStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdApplicationStep.cs index 999d3682993..ba5a225a895 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdApplicationStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdApplicationStep.cs @@ -1,7 +1,9 @@ using System; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.OpenId.Abstractions.Managers; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -11,13 +13,17 @@ namespace OrchardCore.OpenId.Recipes public class OpenIdApplicationStep : IRecipeStepHandler { private readonly IOpenIdApplicationManager _applicationManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; /// /// This recipe step adds an OpenID Connect app. /// - public OpenIdApplicationStep(IOpenIdApplicationManager applicationManager) + public OpenIdApplicationStep( + IOpenIdApplicationManager applicationManager, + IOptions jsonSerializerOptions) { _applicationManager = applicationManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -27,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var app = await _applicationManager.FindByClientIdAsync(model.ClientId); var settings = new OpenIdApplicationSettings() diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdClientSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdClientSettingsStep.cs index 942b245aaeb..a9b8b4afaaa 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdClientSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdClientSettingsStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.OpenId.Services; using OrchardCore.OpenId.Settings; using OrchardCore.Recipes.Models; @@ -14,10 +16,14 @@ namespace OrchardCore.OpenId.Recipes public class OpenIdClientSettingsStep : IRecipeStepHandler { private readonly IOpenIdClientService _clientService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public OpenIdClientSettingsStep(IOpenIdClientService clientService) + public OpenIdClientSettingsStep( + IOpenIdClientService clientService, + IOptions jsonSerializerOptions) { _clientService = clientService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -27,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var settings = await _clientService.LoadSettingsAsync(); settings.Scopes = model.Scopes.Split(' ', ','); diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdScopeStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdScopeStep.cs index 7974664825c..34b1a7d9343 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdScopeStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdScopeStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.OpenId.Abstractions.Descriptors; using OrchardCore.OpenId.Abstractions.Managers; using OrchardCore.Recipes.Models; @@ -11,13 +13,17 @@ namespace OrchardCore.OpenId.Recipes public class OpenIdScopeStep : IRecipeStepHandler { private readonly IOpenIdScopeManager _scopeManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; /// /// This recipe step adds an OpenID Connect scope. /// - public OpenIdScopeStep(IOpenIdScopeManager scopeManager) + public OpenIdScopeStep( + IOpenIdScopeManager scopeManager, + IOptions jsonSerializerOptions) { _scopeManager = scopeManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -27,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var scope = await _scopeManager.FindByNameAsync(model.ScopeName); var descriptor = new OpenIdScopeDescriptor(); var isNew = true; diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdServerSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdServerSettingsStep.cs index fc40623cb37..a3041276692 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdServerSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdServerSettingsStep.cs @@ -1,7 +1,9 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using OrchardCore.OpenId.Services; using OrchardCore.OpenId.Settings; using OrchardCore.Recipes.Models; @@ -15,9 +17,15 @@ namespace OrchardCore.OpenId.Recipes public class OpenIdServerSettingsStep : IRecipeStepHandler { private readonly IOpenIdServerService _serverService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public OpenIdServerSettingsStep(IOpenIdServerService serverService) - => _serverService = serverService; + public OpenIdServerSettingsStep( + IOpenIdServerService serverService, + IOptions jsonSerializerOptions) + { + _serverService = serverService; + _jsonSerializerOptions = jsonSerializerOptions.Value; + } public async Task ExecuteAsync(RecipeExecutionContext context) { @@ -26,7 +34,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var settings = await _serverService.LoadSettingsAsync(); settings.AccessTokenFormat = model.AccessTokenFormat; diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdValidationSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdValidationSettingsStep.cs index e305181a7ca..e6685a8eb45 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdValidationSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Recipes/OpenIdValidationSettingsStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.OpenId.Services; using OrchardCore.OpenId.Settings; using OrchardCore.Recipes.Models; @@ -14,9 +16,15 @@ namespace OrchardCore.OpenId.Recipes public class OpenIdValidationSettingsStep : IRecipeStepHandler { private readonly IOpenIdValidationService _validationService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public OpenIdValidationSettingsStep(IOpenIdValidationService validationService) - => _validationService = validationService; + public OpenIdValidationSettingsStep( + IOpenIdValidationService validationService, + IOptions jsonSerializerOptions) + { + _validationService = validationService; + _jsonSerializerOptions = jsonSerializerOptions.Value; + } public async Task ExecuteAsync(RecipeExecutionContext context) { @@ -25,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); var settings = await _validationService.LoadSettingsAsync(); settings.Tenant = model.Tenant; diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs index 01c7eb42959..6d11ccf19dc 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdServerService.cs @@ -70,7 +70,7 @@ private OpenIdServerSettings GetSettingsFromContainer(ISite container) { if (container.Properties.TryGetPropertyValue(nameof(OpenIdServerSettings), out var settings)) { - return settings.ToObject(); + return settings.ToObject(_jsonSerializerOptions); } // If the OpenID server settings haven't been populated yet, the authorization, diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdValidationService.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdValidationService.cs index 9d46ef87803..2aa62efd93b 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdValidationService.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdValidationService.cs @@ -59,7 +59,7 @@ private OpenIdValidationSettings GetSettingsFromContainer(ISite container) { if (container.Properties.TryGetPropertyValue(nameof(OpenIdValidationSettings), out var settings)) { - return settings.ToObject(); + return settings.ToObject(_jsonSerializerOptions); } // If the OpenID validation settings haven't been populated yet, assume the validation diff --git a/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs b/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs index a07894ada91..db78672c56b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Placements/Recipes/PlacementStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.DisplayManagement.Descriptors.ShapePlacementStrategy; using OrchardCore.Placements.Services; using OrchardCore.Recipes.Models; @@ -14,10 +16,14 @@ namespace OrchardCore.Placements.Recipes public class PlacementStep : IRecipeStepHandler { private readonly PlacementsManager _placementsManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public PlacementStep(PlacementsManager placementsManager) + public PlacementStep( + PlacementsManager placementsManager, + IOptions jsonSerializerOptions) { _placementsManager = placementsManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -32,7 +38,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) foreach (var property in templates) { var name = property.Key; - var value = property.Value.ToObject(); + var value = property.Value.ToObject(_jsonSerializerOptions); await _placementsManager.UpdateShapePlacementsAsync(name, value); } diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs index 56f988b7913..e46b2baaf17 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Recipes/QueryStep.cs @@ -1,9 +1,11 @@ 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.Logging; +using Microsoft.Extensions.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -16,15 +18,18 @@ public class QueryStep : IRecipeStepHandler { private readonly IQueryManager _queryManager; private readonly IEnumerable _querySources; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly ILogger _logger; public QueryStep( IQueryManager queryManager, IEnumerable querySources, + IOptions jsonSerializerOptions, ILogger logger) { _queryManager = queryManager; _querySources = querySources; + _jsonSerializerOptions = jsonSerializerOptions.Value; _logger = logger; } @@ -35,7 +40,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); foreach (var token in model.Queries.Cast()) { @@ -49,7 +54,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) continue; } - var query = token.ToObject(sample.GetType()) as Query; + var query = token.ToObject(sample.GetType(), _jsonSerializerOptions) as Query; await _queryManager.SaveQueryAsync(query.Name, query); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/CommandStep.cs b/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/CommandStep.cs index 0a98156f2bc..20ed9c8becd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/CommandStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/CommandStep.cs @@ -1,8 +1,10 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Cysharp.Text; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using OrchardCore.Environment.Commands; using OrchardCore.Environment.Commands.Parameters; using OrchardCore.Recipes.Models; @@ -18,16 +20,19 @@ public class CommandStep : IRecipeStepHandler private readonly ICommandManager _commandManager; private readonly ICommandParser _commandParser; private readonly ICommandParametersParser _commandParameterParser; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly ILogger _logger; public CommandStep(ICommandManager commandManager, ICommandParser commandParser, ICommandParametersParser commandParameterParser, + IOptions jsonSerializerOptions, ILogger logger) { _commandManager = commandManager; _commandParser = commandParser; _commandParameterParser = commandParameterParser; + _jsonSerializerOptions = jsonSerializerOptions.Value; _logger = logger; } @@ -38,7 +43,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var step = context.Step.ToObject(); + var step = context.Step.ToObject(_jsonSerializerOptions); foreach (var command in step.Commands) { diff --git a/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/RecipesStep.cs b/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/RecipesStep.cs index 49c4199d6c2..db68b51eeae 100644 --- a/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/RecipesStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Recipes/RecipeSteps/RecipesStep.cs @@ -1,8 +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.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -14,10 +16,14 @@ namespace OrchardCore.Recipes.RecipeSteps public class RecipesStep : IRecipeStepHandler { private readonly IEnumerable _recipeHarvesters; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public RecipesStep(IEnumerable recipeHarvesters) + public RecipesStep( + IEnumerable recipeHarvesters, + IOptions jsonSerializerOptions) { _recipeHarvesters = recipeHarvesters; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -27,7 +33,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var step = context.Step.ToObject(); + var step = context.Step.ToObject(_jsonSerializerOptions); var recipeCollections = await Task.WhenAll(_recipeHarvesters.Select(harvester => harvester.HarvestRecipesAsync())); var recipes = recipeCollections.SelectMany(recipe => recipe).ToDictionary(recipe => recipe.Name); diff --git a/src/OrchardCore.Modules/OrchardCore.Roles/Recipes/RolesStep.cs b/src/OrchardCore.Modules/OrchardCore.Roles/Recipes/RolesStep.cs index 22368501705..d6a46155aba 100644 --- a/src/OrchardCore.Modules/OrchardCore.Roles/Recipes/RolesStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Roles/Recipes/RolesStep.cs @@ -1,8 +1,10 @@ using System; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Security; @@ -16,10 +18,14 @@ namespace OrchardCore.Roles.Recipes public class RolesStep : IRecipeStepHandler { private readonly RoleManager _roleManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public RolesStep(RoleManager roleManager) + public RolesStep( + RoleManager roleManager, + IOptions jsonSerializerOptions) { _roleManager = roleManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -29,12 +35,14 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); foreach (var importedRole in model.Roles) { if (string.IsNullOrWhiteSpace(importedRole.Name)) + { continue; + } var role = (Role)await _roleManager.FindByNameAsync(importedRole.Name); var isNewRole = role == null; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ContentPickerFieldElasticEditorSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ContentPickerFieldElasticEditorSettingsDriver.cs index f8e99254417..6f0e78fdfaa 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ContentPickerFieldElasticEditorSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ContentPickerFieldElasticEditorSettingsDriver.cs @@ -1,6 +1,8 @@ using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; using OrchardCore.DisplayManagement.Views; @@ -12,17 +14,21 @@ namespace OrchardCore.Search.Elasticsearch.Drivers public class ContentPickerFieldElasticEditorSettingsDriver : ContentPartFieldDefinitionDisplayDriver { private readonly ElasticIndexSettingsService _elasticIndexSettingsService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ContentPickerFieldElasticEditorSettingsDriver(ElasticIndexSettingsService elasticIndexSettingsService) + public ContentPickerFieldElasticEditorSettingsDriver( + ElasticIndexSettingsService elasticIndexSettingsService, + IOptions jsonSerializerOptions) { _elasticIndexSettingsService = elasticIndexSettingsService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("ContentPickerFieldElasticEditorSettings_Edit", async model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Index = settings.Index; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexRebuildStep.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexRebuildStep.cs index 3131c9a8638..a369edd8123 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexRebuildStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexRebuildStep.cs @@ -1,8 +1,10 @@ using System; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OrchardCore.BackgroundJobs; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -14,6 +16,13 @@ namespace OrchardCore.Search.Lucene.Recipes /// public class LuceneIndexRebuildStep : IRecipeStepHandler { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public LuceneIndexRebuildStep(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public async Task ExecuteAsync(RecipeExecutionContext context) { if (!string.Equals(context.Name, "lucene-index-rebuild", StringComparison.OrdinalIgnoreCase)) @@ -21,7 +30,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); if (model.IncludeAll || model.Indices.Length > 0) { diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexResetStep.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexResetStep.cs index 62b17fd72d3..6cc67fc34ac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexResetStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexResetStep.cs @@ -1,8 +1,10 @@ using System; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OrchardCore.BackgroundJobs; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -14,6 +16,13 @@ namespace OrchardCore.Search.Lucene.Recipes /// public class LuceneIndexResetStep : IRecipeStepHandler { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public LuceneIndexResetStep(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public async Task ExecuteAsync(RecipeExecutionContext context) { if (!string.Equals(context.Name, "lucene-index-reset", StringComparison.OrdinalIgnoreCase)) @@ -21,7 +30,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); if (model.IncludeAll || model.Indices.Length > 0) { diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs index 0dd0611145c..98e1de31ab9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Recipes/LuceneIndexStep.cs @@ -1,8 +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.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Search.Lucene.Model; @@ -15,15 +17,18 @@ namespace OrchardCore.Search.Lucene.Recipes public class LuceneIndexStep : IRecipeStepHandler { private readonly LuceneIndexingService _luceneIndexingService; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly LuceneIndexManager _luceneIndexManager; public LuceneIndexStep( LuceneIndexingService luceneIndexingService, + IOptions jsonSerializerOptions, LuceneIndexManager luceneIndexManager ) { _luceneIndexManager = luceneIndexManager; _luceneIndexingService = luceneIndexingService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -38,7 +43,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) { foreach (var index in jsonArray) { - var luceneIndexSettings = index.ToObject>().FirstOrDefault(); + var luceneIndexSettings = index.ToObject>(_jsonSerializerOptions).FirstOrDefault(); if (!_luceneIndexManager.Exists(luceneIndexSettings.Key)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Settings/ContentPickerFieldLuceneEditorSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Settings/ContentPickerFieldLuceneEditorSettingsDriver.cs index 9447a0be542..6fc00b3552d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Settings/ContentPickerFieldLuceneEditorSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Settings/ContentPickerFieldLuceneEditorSettingsDriver.cs @@ -1,6 +1,8 @@ using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; using OrchardCore.DisplayManagement.Views; @@ -10,17 +12,21 @@ namespace OrchardCore.Search.Lucene.Settings public class ContentPickerFieldLuceneEditorSettingsDriver : ContentPartFieldDefinitionDisplayDriver { private readonly LuceneIndexSettingsService _luceneIndexSettingsService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ContentPickerFieldLuceneEditorSettingsDriver(LuceneIndexSettingsService luceneIndexSettingsService) + public ContentPickerFieldLuceneEditorSettingsDriver( + LuceneIndexSettingsService luceneIndexSettingsService, + IOptions jsonSerializerOptions) { _luceneIndexSettingsService = luceneIndexSettingsService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("ContentPickerFieldLuceneEditorSettings_Edit", async model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Index = settings.Index; model.Indices = (await _luceneIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray(); diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/Recipes/SettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Settings/Recipes/SettingsStep.cs index 4af28a27e2c..09845153c32 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/Recipes/SettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/Recipes/SettingsStep.cs @@ -1,7 +1,9 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -13,10 +15,14 @@ namespace OrchardCore.Settings.Recipes public class SettingsStep : IRecipeStepHandler { private readonly ISiteService _siteService; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public SettingsStep(ISiteService siteService) + public SettingsStep( + ISiteService siteService, + IOptions jsonSerializerOptions) { _siteService = siteService; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -90,7 +96,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) break; case "HomeRoute": - site.HomeRoute = property.Value.ToObject(); + site.HomeRoute = property.Value.ToObject(_jsonSerializerOptions); break; case "CacheMode": diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs index 35540d8bd48..8a903c6ac56 100644 --- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Recipes/ShortcodeTemplateStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Shortcodes.Models; @@ -14,10 +16,14 @@ namespace OrchardCore.Shortcodes.Recipes public class ShortcodeTemplateStep : IRecipeStepHandler { private readonly ShortcodeTemplatesManager _templatesManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public ShortcodeTemplateStep(ShortcodeTemplatesManager templatesManager) + public ShortcodeTemplateStep( + ShortcodeTemplatesManager templatesManager, + IOptions jsonSerializerOptions) { _templatesManager = templatesManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -32,7 +38,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) foreach (var property in templates) { var name = property.Key; - var value = property.Value.ToObject(); + var value = property.Value.ToObject(_jsonSerializerOptions); await _templatesManager.UpdateShortcodeTemplateAsync(name, value); } diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs index edfc620e226..141a13450ad 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs @@ -1,7 +1,9 @@ using System; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Sitemaps.Models; @@ -15,10 +17,14 @@ namespace OrchardCore.Sitemaps.Recipes public class SitemapsStep : IRecipeStepHandler { private readonly ISitemapManager _sitemapManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public SitemapsStep(ISitemapManager sitemapManager) + public SitemapsStep( + ISitemapManager sitemapManager, + IOptions jsonSerializerOptions) { _sitemapManager = sitemapManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -28,11 +34,11 @@ public async Task ExecuteAsync(RecipeExecutionContext context) return; } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(_jsonSerializerOptions); foreach (var token in model.Data.Cast()) { - var sitemap = token.ToObject(); + var sitemap = token.ToObject(_jsonSerializerOptions); await _sitemapManager.UpdateSitemapAsync(sitemap); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs index d33fcdce8c1..76060d39f41 100644 --- a/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; using OrchardCore.DisplayManagement.Views; @@ -10,11 +12,18 @@ namespace OrchardCore.Spatial.Drivers { public class GeoPointFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public GeoPointFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("GeoPointFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.Required = settings.Required; diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs index 2013e4c3005..e6475064ebb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs @@ -187,7 +187,7 @@ public async Task Edit(string taxonomyContentItemId, string taxon } // Look for the target taxonomy item in the hierarchy. - JsonObject taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId); + var taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId); // Couldn't find targeted taxonomy item. if (taxonomyItem == null) @@ -195,7 +195,7 @@ public async Task Edit(string taxonomyContentItemId, string taxon return NotFound(); } - var contentItem = taxonomyItem.ToObject(); + var contentItem = taxonomyItem.ToObject(_jsonSerializerOptions); contentItem.Weld(); contentItem.Alter(t => t.TaxonomyContentItemId = taxonomyContentItemId); @@ -240,7 +240,7 @@ public async Task EditPost(string taxonomyContentItemId, string t } // Look for the target taxonomy item in the hierarchy. - JsonObject taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId); + var taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId); // Couldn't find targeted taxonomy item. if (taxonomyItem == null) @@ -248,7 +248,7 @@ public async Task EditPost(string taxonomyContentItemId, string t return NotFound(); } - var existing = taxonomyItem.ToObject(); + var existing = taxonomyItem.ToObject(_jsonSerializerOptions); // Create a new item to take into account the current type definition. var contentItem = await _contentManager.NewAsync(existing.ContentType); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs index 865ea3d37a4..8c5308fd83f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Cysharp.Text; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Contents.ViewModels; @@ -28,17 +30,21 @@ public class TaxonomyContentsAdminListDisplayDriver : DisplayDriver jsonSerializerOptions, IStringLocalizer stringLocalizer) { _siteService = siteService; _contentManager = contentManager; _contentDefinitionManager = contentDefinitionManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; S = stringLocalizer; } @@ -132,7 +138,7 @@ public override async Task UpdateAsync(ContentOptionsViewModel m return await EditAsync(model, updater); } - private static void PopulateTermEntries(List termEntries, IEnumerable contentItems, int level) + private void PopulateTermEntries(List termEntries, IEnumerable contentItems, int level) { foreach (var contentItem in contentItems) { @@ -140,7 +146,7 @@ private static void PopulateTermEntries(List termEntries, IEnum if (((JsonObject)contentItem.Content)["Terms"] is JsonArray termsArray) { - children = termsArray.ToObject(); + children = termsArray.ToObject(_jsonSerializerOptions); } var termEntry = new FilterTermEntry diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs index 0654ec92aa9..4fa929a539a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.ContentManagement.Display.Models; @@ -18,13 +20,16 @@ namespace OrchardCore.Taxonomies.Drivers public class TaxonomyFieldDisplayDriver : ContentFieldDisplayDriver { private readonly IContentManager _contentManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; protected readonly IStringLocalizer S; public TaxonomyFieldDisplayDriver( IContentManager contentManager, + IOptions jsonSerializerOptions, IStringLocalizer localizer) { _contentManager = contentManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; S = localizer; } @@ -50,7 +55,7 @@ public override IDisplayResult Edit(TaxonomyField field, BuildFieldEditorContext if (model.Taxonomy != null) { var termEntries = new List(); - TaxonomyFieldDriverHelper.PopulateTermEntries(termEntries, field, model.Taxonomy.As().Terms, 0); + TaxonomyFieldDriverHelper.PopulateTermEntries(termEntries, field, model.Taxonomy.As().Terms, 0, _jsonSerializerOptions); model.TermEntries = termEntries; model.UniqueValue = termEntries.FirstOrDefault(x => x.Selected)?.ContentItemId; diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs index 566be2ef874..7ca0789c8a4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using OrchardCore.ContentManagement; using OrchardCore.Taxonomies.Fields; @@ -14,7 +15,7 @@ public static class TaxonomyFieldDriverHelper /// Populates a list of with the hierarchy of terms. /// The list is ordered so that roots appear right before their child terms. /// - public static void PopulateTermEntries(List termEntries, TaxonomyField field, IEnumerable contentItems, int level) + public static void PopulateTermEntries(List termEntries, TaxonomyField field, IEnumerable contentItems, int level, JsonSerializerOptions jsonSerializerOptions = null) { foreach (var contentItem in contentItems) { @@ -22,7 +23,7 @@ public static void PopulateTermEntries(List termEntries, TaxonomyFiel if (((JsonObject)contentItem.Content)["Terms"] is JsonArray termsArray) { - children = termsArray.ToObject(); + children = termsArray.ToObject(jsonSerializerOptions); } var termEntry = new TermEntry @@ -38,7 +39,7 @@ public static void PopulateTermEntries(List termEntries, TaxonomyFiel if (children.Length > 0) { - PopulateTermEntries(termEntries, field, children, level + 1); + PopulateTermEntries(termEntries, field, children, level + 1, jsonSerializerOptions); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs index cefbac24312..75f77d5c947 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs @@ -5,6 +5,7 @@ using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.ContentManagement.Display.Models; @@ -21,14 +22,18 @@ namespace OrchardCore.Taxonomies.Drivers public class TaxonomyFieldTagsDisplayDriver : ContentFieldDisplayDriver { private readonly IContentManager _contentManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; + protected readonly IStringLocalizer S; public TaxonomyFieldTagsDisplayDriver( IContentManager contentManager, - IStringLocalizer s) + IOptions jsonSerializerOptions, + IStringLocalizer stringLocalizer) { _contentManager = contentManager; - S = s; + _jsonSerializerOptions = jsonSerializerOptions.Value; + S = stringLocalizer; } public override IDisplayResult Display(TaxonomyField field, BuildFieldDisplayContext context) @@ -53,7 +58,7 @@ public override IDisplayResult Edit(TaxonomyField field, BuildFieldEditorContext if (model.Taxonomy != null) { var termEntries = new List(); - TaxonomyFieldDriverHelper.PopulateTermEntries(termEntries, field, model.Taxonomy.As().Terms, 0); + TaxonomyFieldDriverHelper.PopulateTermEntries(termEntries, field, model.Taxonomy.As().Terms, 0, _jsonSerializerOptions); var tagTermEntries = termEntries.Select(te => new TagTermEntry { ContentItemId = te.ContentItemId, @@ -105,7 +110,8 @@ public override async Task UpdateAsync(TaxonomyField field, IUpd { var term = TaxonomyOrchardHelperExtensions.FindTerm( (JsonArray)taxonomy.Content["TaxonomyPart"]["Terms"], - termContentItemId); + termContentItemId, + _jsonSerializerOptions); terms.Add(term); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs index dd186c779e6..8f1ccd6320b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs @@ -103,7 +103,7 @@ private JsonObject GetTaxonomyItemAt(List taxonomyItems, int[] inde taxonomyItem = taxonomyItems[index]; var terms = (JsonArray)taxonomyItem.Content["Terms"]; - taxonomyItems = terms?.ToObject>(); + taxonomyItems = terms?.ToObject>(_jsonSerializerOptions); } var newObj = JObject.FromObject(taxonomyItem, _jsonSerializerOptions); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs index ad4942e525d..69c36533813 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Nodes; using GraphQL.Types; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OrchardCore.Apis.GraphQL; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.GraphQL.Queries.Types; @@ -11,7 +13,7 @@ namespace OrchardCore.Taxonomies.GraphQL { public class TaxonomyFieldQueryObjectType : ObjectGraphType { - public TaxonomyFieldQueryObjectType() + public TaxonomyFieldQueryObjectType(IOptions jsonSerializerOptions) { Name = nameof(TaxonomyField); @@ -51,7 +53,8 @@ public TaxonomyFieldQueryObjectType() { var term = TaxonomyOrchardHelperExtensions.FindTerm( (JsonArray)taxonomy.Content["TaxonomyPart"]["Terms"], - termContentItemId); + termContentItemId, + jsonSerializerOptions.Value); terms.Add(term); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs index a533078fa5e..64a5bd37979 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs @@ -1,6 +1,7 @@ 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.DependencyInjection; @@ -19,8 +20,9 @@ public static class TaxonomyOrchardHelperExtensions /// The . /// The taxonomy content item id. /// The term content item id. + /// /// A content item id null if it was not found. - public static async Task GetTaxonomyTermAsync(this IOrchardHelper orchardHelper, string taxonomyContentItemId, string termContentItemId) + public static async Task GetTaxonomyTermAsync(this IOrchardHelper orchardHelper, string taxonomyContentItemId, string termContentItemId, JsonSerializerOptions jsonSerializerOptions) { var contentManager = orchardHelper.HttpContext.RequestServices.GetService(); var taxonomy = await contentManager.GetAsync(taxonomyContentItemId); @@ -30,7 +32,7 @@ public static async Task GetTaxonomyTermAsync(this IOrchardHelper o return null; } - return FindTerm((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId); + return FindTerm((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId, jsonSerializerOptions); } /// @@ -39,8 +41,9 @@ public static async Task GetTaxonomyTermAsync(this IOrchardHelper o /// The . /// The taxonomy content item id. /// The term content item id. + /// The serializer options. /// A list content items. - public static async Task> GetInheritedTermsAsync(this IOrchardHelper orchardHelper, string taxonomyContentItemId, string termContentItemId) + public static async Task> GetInheritedTermsAsync(this IOrchardHelper orchardHelper, string taxonomyContentItemId, string termContentItemId, JsonSerializerOptions jsonSerializerOptions) { var contentManager = orchardHelper.HttpContext.RequestServices.GetService(); var taxonomy = await contentManager.GetAsync(taxonomyContentItemId); @@ -52,7 +55,7 @@ public static async Task> GetInheritedTermsAsync(this IOrchard var terms = new List(); - FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId, terms); + FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId, terms, jsonSerializerOptions); return terms; } @@ -70,7 +73,7 @@ public static async Task> QueryCategorizedContentItemsA return await contentManager.LoadAsync(contentItems); } - internal static ContentItem FindTerm(JsonArray termsArray, string termContentItemId) + internal static ContentItem FindTerm(JsonArray termsArray, string termContentItemId, JsonSerializerOptions jsonSerializerOptions) { foreach (var term in termsArray.Cast()) { @@ -78,12 +81,12 @@ internal static ContentItem FindTerm(JsonArray termsArray, string termContentIte if (contentItemId == termContentItemId) { - return term.ToObject(); + return term.ToObject(jsonSerializerOptions); } if (term["Terms"] is JsonArray children) { - var found = FindTerm(children, termContentItemId); + var found = FindTerm(children, termContentItemId, jsonSerializerOptions); if (found != null) { @@ -95,7 +98,7 @@ internal static ContentItem FindTerm(JsonArray termsArray, string termContentIte return null; } - internal static bool FindTermHierarchy(JsonArray termsArray, string termContentItemId, List terms) + internal static bool FindTermHierarchy(JsonArray termsArray, string termContentItemId, List terms, JsonSerializerOptions jsonSerializerOptions) { foreach (var term in termsArray.Cast()) { @@ -110,11 +113,11 @@ internal static bool FindTermHierarchy(JsonArray termsArray, string termContentI if (term["Terms"] is JsonArray children) { - var found = FindTermHierarchy(children, termContentItemId, terms); + var found = FindTermHierarchy(children, termContentItemId, terms, jsonSerializerOptions); if (found) { - terms.Add(term.ToObject()); + terms.Add(term.ToObject(jsonSerializerOptions)); return true; } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs index cb0882fbded..371ef416f24 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Contents.Indexing; using OrchardCore.Indexing; @@ -13,10 +15,14 @@ namespace OrchardCore.Taxonomies.Indexing public class TaxonomyFieldIndexHandler : ContentFieldIndexHandler { private readonly IServiceProvider _serviceProvider; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public TaxonomyFieldIndexHandler(IServiceProvider serviceProvider) + public TaxonomyFieldIndexHandler( + IServiceProvider serviceProvider, + IOptions jsonSerializerOptions) { _serviceProvider = serviceProvider; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public override async Task BuildIndexAsync(TaxonomyField field, BuildFieldIndexContext context) @@ -42,7 +48,7 @@ public override async Task BuildIndexAsync(TaxonomyField field, BuildFieldIndexC var inheritedContentItems = new List(); foreach (var contentItemId in field.TermContentItemIds) { - TaxonomyOrchardHelperExtensions.FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, contentItemId, inheritedContentItems); + TaxonomyOrchardHelperExtensions.FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, contentItemId, inheritedContentItems, _jsonSerializerOptions); } 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 a0500909d4e..b63bed11069 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Data; @@ -26,12 +28,16 @@ public class TaxonomyIndex : MapIndex public class TaxonomyIndexProvider : IndexProvider, IScopedIndexProvider { private readonly IServiceProvider _serviceProvider; + private readonly JsonSerializerOptions _jsonSerializerOptions; private readonly HashSet _ignoredTypes = []; private IContentDefinitionManager _contentDefinitionManager; - public TaxonomyIndexProvider(IServiceProvider serviceProvider) + public TaxonomyIndexProvider( + IServiceProvider serviceProvider, + IOptions jsonSerializerOptions) { _serviceProvider = serviceProvider; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public override void Describe(DescribeContext context) @@ -92,7 +98,7 @@ public override void Describe(DescribeContext context) continue; } - var field = ((JsonObject)jField).ToObject(); + var field = ((JsonObject)jField).ToObject(_jsonSerializerOptions); 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 7bb674db146..cb5f5f45a13 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs @@ -1,8 +1,10 @@ using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Fluid; using Fluid.Values; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Liquid; @@ -11,10 +13,14 @@ namespace OrchardCore.Taxonomies.Liquid public class InheritedTermsFilter : ILiquidFilter { private readonly IContentManager _contentManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public InheritedTermsFilter(IContentManager contentManager) + public InheritedTermsFilter( + IContentManager contentManager, + IOptions jsonSerializerOptions) { _contentManager = contentManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async ValueTask ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx) @@ -36,7 +42,7 @@ public async ValueTask ProcessAsync(FluidValue input, FilterArgument var terms = new List(); - TaxonomyOrchardHelperExtensions.FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId, terms); + TaxonomyOrchardHelperExtensions.FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId, terms, _jsonSerializerOptions); 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 ad2f392701a..8c3ef97b44c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Fluid; using Fluid.Values; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.Liquid; using OrchardCore.Taxonomies.Fields; @@ -13,10 +15,14 @@ namespace OrchardCore.Taxonomies.Liquid public class TaxonomyTermsFilter : ILiquidFilter { private readonly IContentManager _contentManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public TaxonomyTermsFilter(IContentManager contentManager) + public TaxonomyTermsFilter( + IContentManager contentManager, + IOptions jsonSerializerOptions) { _contentManager = contentManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async ValueTask ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx) @@ -60,7 +66,8 @@ public async ValueTask ProcessAsync(FluidValue input, FilterArgument { var term = TaxonomyOrchardHelperExtensions.FindTerm( (JsonArray)taxonomy.Content["TaxonomyPart"]["Terms"], - termContentItemId); + termContentItemId, + _jsonSerializerOptions); if (term is not null) { diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs index 15aa789f3b2..02cc1df20b2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Migrations.cs @@ -1,4 +1,6 @@ +using System.Text.Json; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.ContentManagement.Records; @@ -13,10 +15,14 @@ namespace OrchardCore.Taxonomies public class Migrations : DataMigration { private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public Migrations(IContentDefinitionManager contentDefinitionManager) + public Migrations( + IContentDefinitionManager contentDefinitionManager, + IOptions jsonSerializerOptions) { _contentDefinitionManager = contentDefinitionManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task CreateAsync() @@ -84,7 +90,7 @@ await SchemaBuilder.AlterIndexTableAsync(table => table // This code can be removed in a later version. public async Task UpdateFrom1Async() { - await _contentDefinitionManager.MigrateFieldSettingsAsync(); + await _contentDefinitionManager.MigrateFieldSettingsAsync(_jsonSerializerOptions); return 2; } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs index e70cc65b180..5cc0063cb18 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; using OrchardCore.DisplayManagement.Views; @@ -9,11 +11,18 @@ namespace OrchardCore.Taxonomies.Settings { public class TaxonomyFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public TaxonomyFieldSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("TaxonomyFieldSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Hint = settings.Hint; model.Required = settings.Required; diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs index b40c5972991..4bf380ebbff 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs @@ -1,5 +1,7 @@ +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; using OrchardCore.DisplayManagement.Views; @@ -9,15 +11,21 @@ namespace OrchardCore.Taxonomies.Settings { public class TaxonomyFieldTagsEditorSettingsDriver : ContentPartFieldDefinitionDisplayDriver { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public TaxonomyFieldTagsEditorSettingsDriver(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("TaxonomyFieldTagsEditorSettings_Edit", model => { - var settings = partFieldDefinition.Settings.ToObject(); + var settings = partFieldDefinition.Settings.ToObject(_jsonSerializerOptions); model.Open = settings.Open; - }) - .Location("Content"); + }).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 bbd5edeaec5..47a95ba3bfb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using OrchardCore.ContentManagement; using OrchardCore.DisplayManagement; using OrchardCore.DisplayManagement.Descriptors; @@ -16,6 +18,13 @@ namespace OrchardCore.Taxonomies { public class TermShapes : ShapeTableProvider { + private readonly JsonSerializerOptions _jsonSerializerOptions; + + public TermShapes(IOptions jsonSerializerOptions) + { + _jsonSerializerOptions = jsonSerializerOptions.Value; + } + public override ValueTask DiscoverAsync(ShapeTableBuilder builder) { // Add standard alternates to a TermPart because it is rendered by a content display driver not a part display driver. @@ -89,7 +98,7 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder) var termContentItemId = termShape.GetProperty("TermContentItemId"); if (!string.IsNullOrEmpty(termContentItemId)) { - level = FindTerm((JsonArray)taxonomyContentItem.Content.TaxonomyPart.Terms, termContentItemId, level, out var termContentItem); + level = FindTerm((JsonArray)taxonomyContentItem.Content.TaxonomyPart.Terms, termContentItemId, level, _jsonSerializerOptions, out var termContentItem); if (termContentItem == null) { @@ -135,7 +144,7 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder) ContentItem[] childTerms = null; if (((JsonObject)termContentItem.Content)["Terms"] is JsonArray termsArray) { - childTerms = termsArray.ToObject(); + childTerms = termsArray.ToObject(_jsonSerializerOptions); } var shape = await shapeFactory.CreateAsync("TermItem", Arguments.From(new @@ -173,7 +182,7 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder) ContentItem[] childTerms = null; if (((JsonObject)termContentItem.Content)["Terms"] is JsonArray termsArray) { - childTerms = termsArray.ToObject(); + childTerms = termsArray.ToObject(_jsonSerializerOptions); } var shape = await shapeFactory.CreateAsync("TermItem", Arguments.From(new { @@ -250,21 +259,21 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder) return ValueTask.CompletedTask; } - private static int FindTerm(JsonArray termsArray, string termContentItemId, int level, out ContentItem contentItem) + private static int FindTerm(JsonArray termsArray, string termContentItemId, int level, JsonSerializerOptions jsonSerializerOptions, out ContentItem contentItem) { foreach (var term in termsArray.Cast()) { var contentItemId = term["ContentItemId"]?.ToString(); if (contentItemId == termContentItemId) { - contentItem = term.ToObject(); + contentItem = term.ToObject(jsonSerializerOptions); return level; } if (term["Terms"] is JsonArray children) { level += 1; - level = FindTerm(children, termContentItemId, level, out var foundContentItem); + level = FindTerm(children, termContentItemId, level, jsonSerializerOptions, out var foundContentItem); if (foundContentItem != null) { diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml index 3f7a4ae7e53..8b49bb8e499 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml @@ -1,8 +1,10 @@ @using System.Text.Json.Nodes +@using Microsoft.Extensions.Options +@using System.Text.Json @inject OrchardCore.ContentManagement.Display.IContentItemDisplayManager ContentItemDisplayManager @inject OrchardCore.DisplayManagement.ModelBinding.IUpdateModelAccessor ModelUpdaterAccessor - +@inject IOptions JsonSerializerOptions @{ ContentItem contentItem = Model.ContentItem; var termsArray = (JsonArray)contentItem.Content.Terms; @@ -19,29 +21,29 @@ } @@ -54,7 +56,7 @@ } - + diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/TaxonomyField.cshtml b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/TaxonomyField.cshtml index fa19af23b26..d26cc3e72d9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/TaxonomyField.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/TaxonomyField.cshtml @@ -1,6 +1,9 @@ @model OrchardCore.Taxonomies.ViewModels.DisplayTaxonomyFieldViewModel +@using Microsoft.Extensions.Options @using OrchardCore.Mvc.Utilities +@using System.Text.Json +@inject IOptions JsonSerializerOptions @{ var name = (Model.PartFieldDefinition.PartDefinition.Name + "-" + Model.PartFieldDefinition.Name).HtmlClassify(); } @@ -8,7 +11,7 @@
@foreach (var contentItemId in Model.TermContentItemIds) { - var term = await Orchard.GetTaxonomyTermAsync(Model.TaxonomyContentItemId, contentItemId); + var term = await Orchard.GetTaxonomyTermAsync(Model.TaxonomyContentItemId, contentItemId, JsonSerializerOptions.Value); @term }
diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs index 21709373b7e..115d84a92f4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/Recipes/AdminTemplateStep.cs @@ -1,6 +1,8 @@ using System; +using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Templates.Models; @@ -14,10 +16,14 @@ namespace OrchardCore.Templates.Recipes public class AdminTemplateStep : IRecipeStepHandler { private readonly AdminTemplatesManager _adminTemplatesManager; + private readonly JsonSerializerOptions _jsonSerializerOptions; - public AdminTemplateStep(AdminTemplatesManager templatesManager) + public AdminTemplateStep( + AdminTemplatesManager templatesManager, + IOptions jsonSerializerOptions) { _adminTemplatesManager = templatesManager; + _jsonSerializerOptions = jsonSerializerOptions.Value; } public async Task ExecuteAsync(RecipeExecutionContext context) @@ -32,7 +38,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) foreach (var property in templates) { var name = property.Key; - var value = property.Value.ToObject