Skip to content

Commit 9b9f843

Browse files
Migrate JsonPatch from Newtonsoft to System.Text.Json (#671)
* refactor: migrate JsonPatch from Newtonsoft to System.Text.Json (.NET 10)
1 parent 6409f8b commit 9b9f843

13 files changed

Lines changed: 16 additions & 37 deletions

Directory.Packages.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
<PackageVersion Include="Scrutor" Version="7.0.0" />
3737
<PackageVersion Include="StackExchange.Redis" Version="2.10.1" />
3838
<PackageVersion Include="FluentValidation" Version="12.1.1" />
39-
<PackageVersion Include="Microsoft.AspNetCore.JsonPatch" Version="10.0.1" />
40-
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.1" />
39+
<PackageVersion Include="Microsoft.AspNetCore.JsonPatch.SystemTextJson" Version="10.0.1" />
4140
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Facebook" Version="10.0.1" />
4241
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="10.0.1" />
4342
<PackageVersion Include="Braintree" Version="5.38.0" />

src/Modules/Grand.Module.Api/Controllers/BrandController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Grand.Domain.Permissions;
66
using Grand.Domain.Catalog;
77
using MediatR;
8-
using Microsoft.AspNetCore.JsonPatch;
8+
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
99
using Microsoft.AspNetCore.Mvc;
1010
using Microsoft.AspNetCore.Http;
1111
using Grand.Module.Api.Attributes;

src/Modules/Grand.Module.Api/Controllers/CategoryController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Grand.Domain.Permissions;
66
using Grand.Domain.Catalog;
77
using MediatR;
8-
using Microsoft.AspNetCore.JsonPatch;
8+
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
99
using Microsoft.AspNetCore.Mvc;
1010
using Grand.Module.Api.Attributes;
1111
using Microsoft.AspNetCore.Http;

src/Modules/Grand.Module.Api/Controllers/CollectionController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Grand.Module.Api.Queries.Models.Common;
88
using MediatR;
99
using Microsoft.AspNetCore.Http;
10-
using Microsoft.AspNetCore.JsonPatch;
10+
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
1111
using Microsoft.AspNetCore.Mvc;
1212
using Microsoft.AspNetCore.Routing;
1313

src/Modules/Grand.Module.Api/Controllers/CustomerGroupController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Grand.Module.Api.Queries.Models.Common;
88
using MediatR;
99
using Microsoft.AspNetCore.Http;
10-
using Microsoft.AspNetCore.JsonPatch;
10+
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
1111
using Microsoft.AspNetCore.Mvc;
1212
using Microsoft.AspNetCore.Routing;
1313

src/Modules/Grand.Module.Api/Controllers/ProductAttributeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Grand.Module.Api.Queries.Models.Common;
88
using MediatR;
99
using Microsoft.AspNetCore.Http;
10-
using Microsoft.AspNetCore.JsonPatch;
10+
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
1111
using Microsoft.AspNetCore.Mvc;
1212
using Microsoft.AspNetCore.Routing;
1313

src/Modules/Grand.Module.Api/Controllers/ProductController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Grand.Module.Api.Queries.Models.Common;
88
using MediatR;
99
using Microsoft.AspNetCore.Http;
10-
using Microsoft.AspNetCore.JsonPatch;
10+
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
1111
using Microsoft.AspNetCore.Mvc;
1212
using Microsoft.AspNetCore.Routing;
1313

src/Modules/Grand.Module.Api/Controllers/SpecificationAttributeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Grand.Module.Api.Queries.Models.Common;
88
using MediatR;
99
using Microsoft.AspNetCore.Http;
10-
using Microsoft.AspNetCore.JsonPatch;
10+
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
1111
using Microsoft.AspNetCore.Mvc;
1212
using Microsoft.AspNetCore.Routing;
1313

src/Modules/Grand.Module.Api/Extensions/ServiceCollectionExtensions.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,12 @@
1313
using Grand.Module.Api.Queries.Handlers.Common;
1414
using Grand.Module.Api.Queries.Models.Common;
1515
using MediatR;
16-
using Microsoft.AspNetCore.Mvc;
17-
using Microsoft.AspNetCore.Mvc.Formatters;
1816
using Microsoft.Extensions.DependencyInjection;
19-
using Microsoft.Extensions.Options;
2017

2118
namespace Grand.Module.Api.Infrastructure.Extensions
2219
{
2320
public static class ServiceCollectionExtensions
2421
{
25-
public static NewtonsoftJsonPatchInputFormatter GetJsonPatchInputFormatter(this IServiceCollection services)
26-
{
27-
var builder = new ServiceCollection()
28-
.AddLogging()
29-
.AddMvc()
30-
.AddNewtonsoftJson()
31-
.Services.BuildServiceProvider();
32-
33-
return builder
34-
.GetRequiredService<IOptions<MvcOptions>>()
35-
.Value
36-
.InputFormatters
37-
.OfType<NewtonsoftJsonPatchInputFormatter>()
38-
.First();
39-
}
4022
public static void RegisterRequestHandler(this IServiceCollection services)
4123
{
4224
var handlerTypes = new (Type dto, Type entity)[]

src/Modules/Grand.Module.Api/Grand.Module.Api.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
</PropertyGroup>
4242

4343
<ItemGroup>
44-
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" />
45-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
44+
<PackageReference Include="Microsoft.AspNetCore.JsonPatch.SystemTextJson" />
4645
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
4746
<PackageReference Include="Scalar.AspNetCore" />
4847
<PackageReference Include="System.Linq.Dynamic.Core" />

0 commit comments

Comments
 (0)