Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Migrate JsonPatch from Newtonsoft to System.Text.Json (#671)
Krzysztof Pajak9b9f84320f76
diff --git a/Directory.Packages.props b/Directory.Packages.propsindex ab25cfd27..b2786b10f 100644--- a/Directory.Packages.props+++ b/Directory.Packages.props@@ -36,8 +36,7 @@<PackageVersion Include="Scrutor" Version="7.0.0" /><PackageVersion Include="StackExchange.Redis" Version="2.10.1" /><PackageVersion Include="FluentValidation" Version="12.1.1" />- <PackageVersion Include="Microsoft.AspNetCore.JsonPatch" Version="10.0.1" />- <PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.1" />+ <PackageVersion Include="Microsoft.AspNetCore.JsonPatch.SystemTextJson" Version="10.0.1" /><PackageVersion Include="Microsoft.AspNetCore.Authentication.Facebook" Version="10.0.1" /><PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="10.0.1" /><PackageVersion Include="Braintree" Version="5.38.0" />diff --git a/src/Modules/Grand.Module.Api/Controllers/BrandController.cs b/src/Modules/Grand.Module.Api/Controllers/BrandController.csindex 7d22fec2f..2bfc81ef2 100644--- a/src/Modules/Grand.Module.Api/Controllers/BrandController.cs+++ b/src/Modules/Grand.Module.Api/Controllers/BrandController.cs@@ -5,7 +5,7 @@ using Grand.Business.Core.Interfaces.Common.Security;using Grand.Domain.Permissions;using Grand.Domain.Catalog;using MediatR;-using Microsoft.AspNetCore.JsonPatch;+using Microsoft.AspNetCore.JsonPatch.SystemTextJson;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Http;using Grand.Module.Api.Attributes;diff --git a/src/Modules/Grand.Module.Api/Controllers/CategoryController.cs b/src/Modules/Grand.Module.Api/Controllers/CategoryController.csindex 0d1303617..c41b54cd3 100644--- a/src/Modules/Grand.Module.Api/Controllers/CategoryController.cs+++ b/src/Modules/Grand.Module.Api/Controllers/CategoryController.cs@@ -5,7 +5,7 @@ using Grand.Business.Core.Interfaces.Common.Security;using Grand.Domain.Permissions;using Grand.Domain.Catalog;using MediatR;-using Microsoft.AspNetCore.JsonPatch;+using Microsoft.AspNetCore.JsonPatch.SystemTextJson;using Microsoft.AspNetCore.Mvc;using Grand.Module.Api.Attributes;using Microsoft.AspNetCore.Http;diff --git a/src/Modules/Grand.Module.Api/Controllers/CollectionController.cs b/src/Modules/Grand.Module.Api/Controllers/CollectionController.csindex 036645b39..e396d3cbf 100644--- a/src/Modules/Grand.Module.Api/Controllers/CollectionController.cs+++ b/src/Modules/Grand.Module.Api/Controllers/CollectionController.cs@@ -7,7 +7,7 @@ using Grand.Module.Api.DTOs.Catalog;using Grand.Module.Api.Queries.Models.Common;using MediatR;using Microsoft.AspNetCore.Http;-using Microsoft.AspNetCore.JsonPatch;+using Microsoft.AspNetCore.JsonPatch.SystemTextJson;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Routing;diff --git a/src/Modules/Grand.Module.Api/Controllers/CustomerGroupController.cs b/src/Modules/Grand.Module.Api/Controllers/CustomerGroupController.csindex 7f7080181..286b754b6 100644--- a/src/Modules/Grand.Module.Api/Controllers/CustomerGroupController.cs+++ b/src/Modules/Grand.Module.Api/Controllers/CustomerGroupController.cs@@ -7,7 +7,7 @@ using Grand.Module.Api.DTOs.Customers;using Grand.Module.Api.Queries.Models.Common;using MediatR;using Microsoft.AspNetCore.Http;-using Microsoft.AspNetCore.JsonPatch;+using Microsoft.AspNetCore.JsonPatch.SystemTextJson;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Routing;diff --git a/src/Modules/Grand.Module.Api/Controllers/ProductAttributeController.cs b/src/Modules/Grand.Module.Api/Controllers/ProductAttributeController.csindex e932377f0..1122c1ceb 100644--- a/src/Modules/Grand.Module.Api/Controllers/ProductAttributeController.cs+++ b/src/Modules/Grand.Module.Api/Controllers/ProductAttributeController.cs@@ -7,7 +7,7 @@ using Grand.Module.Api.DTOs.Catalog;using Grand.Module.Api.Queries.Models.Common;using MediatR;using Microsoft.AspNetCore.Http;-using Microsoft.AspNetCore.JsonPatch;+using Microsoft.AspNetCore.JsonPatch.SystemTextJson;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Routing;diff --git a/src/Modules/Grand.Module.Api/Controllers/ProductController.cs b/src/Modules/Grand.Module.Api/Controllers/ProductController.csindex d70465307..9ec2af815 100644--- a/src/Modules/Grand.Module.Api/Controllers/ProductController.cs+++ b/src/Modules/Grand.Module.Api/Controllers/ProductController.cs@@ -7,7 +7,7 @@ using Grand.Module.Api.DTOs.Catalog;using Grand.Module.Api.Queries.Models.Common;using MediatR;using Microsoft.AspNetCore.Http;-using Microsoft.AspNetCore.JsonPatch;+using Microsoft.AspNetCore.JsonPatch.SystemTextJson;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Routing;diff --git a/src/Modules/Grand.Module.Api/Controllers/SpecificationAttributeController.cs b/src/Modules/Grand.Module.Api/Controllers/SpecificationAttributeController.csindex 7836c3a1e..4c7dca241 100644--- a/src/Modules/Grand.Module.Api/Controllers/SpecificationAttributeController.cs+++ b/src/Modules/Grand.Module.Api/Controllers/SpecificationAttributeController.cs@@ -7,7 +7,7 @@ using Grand.Module.Api.DTOs.Catalog;using Grand.Module.Api.Queries.Models.Common;using MediatR;using Microsoft.AspNetCore.Http;-using Microsoft.AspNetCore.JsonPatch;+using Microsoft.AspNetCore.JsonPatch.SystemTextJson;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Routing;diff --git a/src/Modules/Grand.Module.Api/Extensions/ServiceCollectionExtensions.cs b/src/Modules/Grand.Module.Api/Extensions/ServiceCollectionExtensions.csindex c9195e699..6afdfbcee 100644--- a/src/Modules/Grand.Module.Api/Extensions/ServiceCollectionExtensions.cs+++ b/src/Modules/Grand.Module.Api/Extensions/ServiceCollectionExtensions.cs@@ -13,30 +13,12 @@ using Grand.Module.Api.DTOs.Shipping;using Grand.Module.Api.Queries.Handlers.Common;using Grand.Module.Api.Queries.Models.Common;using MediatR;-using Microsoft.AspNetCore.Mvc;-using Microsoft.AspNetCore.Mvc.Formatters;using Microsoft.Extensions.DependencyInjection;-using Microsoft.Extensions.Options;namespace Grand.Module.Api.Infrastructure.Extensions{public static class ServiceCollectionExtensions{- public static NewtonsoftJsonPatchInputFormatter GetJsonPatchInputFormatter(this IServiceCollection services)- {- var builder = new ServiceCollection()- .AddLogging()- .AddMvc()- .AddNewtonsoftJson()- .Services.BuildServiceProvider();-- return builder- .GetRequiredService<IOptions<MvcOptions>>()- .Value- .InputFormatters- .OfType<NewtonsoftJsonPatchInputFormatter>()- .First();- }public static void RegisterRequestHandler(this IServiceCollection services){var handlerTypes = new (Type dto, Type entity)[]diff --git a/src/Modules/Grand.Module.Api/Grand.Module.Api.csproj b/src/Modules/Grand.Module.Api/Grand.Module.Api.csprojindex c1fc46b3d..765ced4aa 100644--- a/src/Modules/Grand.Module.Api/Grand.Module.Api.csproj+++ b/src/Modules/Grand.Module.Api/Grand.Module.Api.csproj@@ -41,8 +41,7 @@</PropertyGroup><ItemGroup>- <PackageReference Include="Microsoft.AspNetCore.JsonPatch" />- <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />+ <PackageReference Include="Microsoft.AspNetCore.JsonPatch.SystemTextJson" /><PackageReference Include="Microsoft.AspNetCore.OpenApi" /><PackageReference Include="Scalar.AspNetCore" /><PackageReference Include="System.Linq.Dynamic.Core" />diff --git a/src/Modules/Grand.Module.Api/Infrastructure/OpenApiStartup.cs b/src/Modules/Grand.Module.Api/Infrastructure/OpenApiStartup.csindex e7606dfed..746cc2c6d 100644--- a/src/Modules/Grand.Module.Api/Infrastructure/OpenApiStartup.cs+++ b/src/Modules/Grand.Module.Api/Infrastructure/OpenApiStartup.cs@@ -54,11 +54,6 @@ public class OpenApiStartup : IStartupApplication//register RequestHandlerservices.RegisterRequestHandler();- //Add JsonPatchInputFormatter- services.AddControllers(options =>- {- options.InputFormatters.Insert(0, services.GetJsonPatchInputFormatter());- });services.AddScoped<ModelValidationAttribute>();}}diff --git a/src/Modules/Grand.Module.Api/Infrastructure/Transformers/IgnoreFieldSchemaTransformer.cs b/src/Modules/Grand.Module.Api/Infrastructure/Transformers/IgnoreFieldSchemaTransformer.csindex 91e0b80b3..c81f90f8d 100644--- a/src/Modules/Grand.Module.Api/Infrastructure/Transformers/IgnoreFieldSchemaTransformer.cs+++ b/src/Modules/Grand.Module.Api/Infrastructure/Transformers/IgnoreFieldSchemaTransformer.cs@@ -11,8 +11,8 @@ public class IgnoreFieldSchemaTransformer : IOpenApiSchemaTransformer{var type = context.JsonTypeInfo.Type;- if (!schema.Properties.Any() || type == null) return Task.CompletedTask;-+ if (type == null || schema.Properties == null || !schema.Properties.Any()) return Task.CompletedTask;+var excludedPropertyNames = type.GetProperties().Where(@@ -26,7 +26,7 @@ public class IgnoreFieldSchemaTransformer : IOpenApiSchemaTransformerap => excludedPropertyNames.Any(pn => pn.Equals(ap.Key, StringComparison.InvariantCultureIgnoreCase))- ).Select(ap => ap.Key);+ ).Select(ap => ap.Key).ToList();foreach (var propertyToExclude in excludedSchemaPropertyKey) schema.Properties.Remove(propertyToExclude);diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.jsonindex cb55d2d4a..7ca546b1b 100644--- a/src/Web/Grand.Web/App_Data/appsettings.json+++ b/src/Web/Grand.Web/App_Data/appsettings.json@@ -171,6 +171,8 @@"ClientSecret": ""},//access to the api to web controllers+ //when enabled (Development environment only), API documentation (Scalar) is available at: https://your-domain/scalar/v2+ //locally: https://localhost:44350/scalar/v2"FrontendAPI": {"Enabled": true,"JsonContentType": false,@@ -186,6 +188,8 @@"RefreshTokenExpiryInMinutes": 1440},//api for admin+ //when enabled (Development environment only), API documentation (Scalar) is available at: https://your-domain/scalar/v1+ //locally: https://localhost:44350/scalar/v1"BackendAPI": {"Enabled": true,"SecretKey": "your private secret key to use api",