Skip to content

Commit 4d83ee6

Browse files
authored
Merge pull request #13357 from abpframework/json
Split JSON into `Newtonsoft` & `SystemTextJson` packages.
2 parents 0053226 + 75c568b commit 4d83ee6

File tree

93 files changed

+1347
-1293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1347
-1293
lines changed

docs/en/JSON.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The ABP Framework provides an abstraction to work with JSON. Having such an abst
44
* You can write library independent code. Therefore, you can change the underlying library with the minimum effort and code change.
55
* You can use the predefined converters defined in the ABP without worrying about the underlying library's internal details.
66

7-
> The JSON serialization system is implemented with the [Volo.Abp.Json](https://www.nuget.org/packages/Volo.Abp.Json) NuGet package. Most of the time, you don't need to manually [install it](https://abp.io/package-detail/Volo.Abp.Json) since it comes pre-installed with the [application startup template](Startup-Templates/Application.md).
7+
> The JSON serialization system is implemented with the [Volo.Abp.Json](https://www.nuget.org/packages/Volo.Abp.Json) NuGet package([Volo.Abp.Json.SystemTextJson](https://www.nuget.org/packages/Volo.Abp.Json.SystemTextJson) is the default implementation). Most of the time, you don't need to manually [install it](https://abp.io/package-detail/Volo.Abp.Json) since it comes pre-installed with the [application startup template](Startup-Templates/Application.md).
88
99
## IJsonSerializer
1010

@@ -45,16 +45,24 @@ public class ProductManager
4545
`AbpJsonOptions` type provides options for the JSON operations in the ABP Framework.
4646

4747
Properties:
48-
* **DefaultDateTimeFormat(`string`)**: Default `DateTime` format.
49-
* **UseHybridSerializer(`bool`)**: True by default. Boolean field indicating whether the ABP Framework uses the hybrid approach or not. If the field is true, it will try to use `System.Json.Text` to handle JSON if it can otherwise use the `Newtonsoft.Json.`
50-
* **Providers(`ITypeList<IJsonSerializerProvider>`)**: List of JSON serializer providers implementing the `IJsonSerializerProvider` interface. You can create and add custom serializers to the list, and the ABP Framework uses them automatically. When the `Serialize` or `Deserialize` method is called on the `IJsonSerializer` interface, the ABP Framework calls the `CanHandle` methods of the given providers in reverse order and uses the first provider that returns `true` to do the JSON operation.
48+
* **InputDateTimeFormats(`List<string>`)**: Formats of input JSON date, Empty string means default format. You can provide multiple formats to parse the date.
49+
* **OutputDateTimeFormat(`string`)**: Format of output json date, Null or empty string means default format.
50+
51+
## System Text Json
5152

5253
### AbpSystemTextJsonSerializerOptions
5354

54-
`AbpSystemTextJsonSerializerOptions` provides options for `System.Text.Json` usage.
55+
- **JsonSerializerOptions(`System.Text.Json.JsonSerializerOptions`)**: Global options for System.Text.Json library operations. See [here](https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions) for reference.
5556

56-
Properties:
57+
### AbpSystemTextJsonSerializerModifiersOptions
5758

58-
- **JsonSerializerOptions(`System.Text.Json.JsonSerializerOptions`)**: Global options for System.Text.Json library operations. See [here](https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializeroptions) for reference.
59-
- **UnsupportedTypes(`ITypeList`)**: List of the unsupported types. You can add types of the unsupported types to the list and, the hybrid JSON serializer automatically uses the `Newtonsoft.Json` library instead of `System.Text.Json`.
59+
- **Modifiers(`List<Action<JsonTypeInfo>>`)**: Configure `Modifiers` of `DefaultJsonTypeInfoResolver`. See [here](https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-6/#json-contract-customization) for reference.
60+
61+
62+
## Newtonsoft
63+
64+
Add [Volo.Abp.Json.Newtonsoft](https://www.nuget.org/packages/Volo.Abp.Json.Newtonsoft) packge and depends on `AbpJsonNewtonsoftModule` to replace the `System Text Json`.
65+
66+
#### AbpNewtonsoftJsonSerializerOptions
6067

68+
- **JsonSerializerSettings(`Newtonsoft.Json.JsonSerializerSettings`)**: Global options for Newtonsoft library operations. See [here](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_JsonSerializerSettings.htm) for reference.

framework/Volo.Abp.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.RemoteServices", "
409409
EndProject
410410
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.PlugIn", "test\Volo.Abp.AspNetCore.Mvc.PlugIn\Volo.Abp.AspNetCore.Mvc.PlugIn.csproj", "{C6D6D878-208A-4FD2-822E-365545D8681B}"
411411
EndProject
412+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Json.Newtonsoft", "src\Volo.Abp.Json.Newtonsoft\Volo.Abp.Json.Newtonsoft.csproj", "{9DD41C8F-0886-483C-B98B-C55EAA7F226D}"
413+
EndProject
414+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Json.SystemTextJson", "src\Volo.Abp.Json.SystemTextJson\Volo.Abp.Json.SystemTextJson.csproj", "{0AD06E14-CBFE-4551-8D18-9E921D8F2A87}"
415+
EndProject
416+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Json.Abstractions", "src\Volo.Abp.Json.Abstractions\Volo.Abp.Json.Abstractions.csproj", "{08531C5D-0436-4721-986D-96446CF54316}"
417+
EndProject
418+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.NewtonsoftJson", "src\Volo.Abp.AspNetCore.Mvc.NewtonsoftJson\Volo.Abp.AspNetCore.Mvc.NewtonsoftJson.csproj", "{0CFC9D4F-F12F-4B44-ABCF-AB4A0E9E85B2}"
419+
EndProject
412420
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Dapr", "src\Volo.Abp.Dapr\Volo.Abp.Dapr.csproj", "{192A829F-D608-4E41-8DE0-058E943E453F}"
413421
EndProject
414422
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.EventBus.Dapr", "src\Volo.Abp.EventBus.Dapr\Volo.Abp.EventBus.Dapr.csproj", "{DCC41E99-EBC7-4F19-BA0D-A6F770D8E431}"
@@ -1231,6 +1239,22 @@ Global
12311239
{C6D6D878-208A-4FD2-822E-365545D8681B}.Debug|Any CPU.Build.0 = Debug|Any CPU
12321240
{C6D6D878-208A-4FD2-822E-365545D8681B}.Release|Any CPU.ActiveCfg = Release|Any CPU
12331241
{C6D6D878-208A-4FD2-822E-365545D8681B}.Release|Any CPU.Build.0 = Release|Any CPU
1242+
{9DD41C8F-0886-483C-B98B-C55EAA7F226D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1243+
{9DD41C8F-0886-483C-B98B-C55EAA7F226D}.Debug|Any CPU.Build.0 = Debug|Any CPU
1244+
{9DD41C8F-0886-483C-B98B-C55EAA7F226D}.Release|Any CPU.ActiveCfg = Release|Any CPU
1245+
{9DD41C8F-0886-483C-B98B-C55EAA7F226D}.Release|Any CPU.Build.0 = Release|Any CPU
1246+
{0AD06E14-CBFE-4551-8D18-9E921D8F2A87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1247+
{0AD06E14-CBFE-4551-8D18-9E921D8F2A87}.Debug|Any CPU.Build.0 = Debug|Any CPU
1248+
{0AD06E14-CBFE-4551-8D18-9E921D8F2A87}.Release|Any CPU.ActiveCfg = Release|Any CPU
1249+
{0AD06E14-CBFE-4551-8D18-9E921D8F2A87}.Release|Any CPU.Build.0 = Release|Any CPU
1250+
{08531C5D-0436-4721-986D-96446CF54316}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1251+
{08531C5D-0436-4721-986D-96446CF54316}.Debug|Any CPU.Build.0 = Debug|Any CPU
1252+
{08531C5D-0436-4721-986D-96446CF54316}.Release|Any CPU.ActiveCfg = Release|Any CPU
1253+
{08531C5D-0436-4721-986D-96446CF54316}.Release|Any CPU.Build.0 = Release|Any CPU
1254+
{0CFC9D4F-F12F-4B44-ABCF-AB4A0E9E85B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1255+
{0CFC9D4F-F12F-4B44-ABCF-AB4A0E9E85B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
1256+
{0CFC9D4F-F12F-4B44-ABCF-AB4A0E9E85B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
1257+
{0CFC9D4F-F12F-4B44-ABCF-AB4A0E9E85B2}.Release|Any CPU.Build.0 = Release|Any CPU
12341258
{192A829F-D608-4E41-8DE0-058E943E453F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12351259
{192A829F-D608-4E41-8DE0-058E943E453F}.Debug|Any CPU.Build.0 = Debug|Any CPU
12361260
{192A829F-D608-4E41-8DE0-058E943E453F}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -1461,6 +1485,10 @@ Global
14611485
{3683340D-92F5-4B14-B77B-34A163333309} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
14621486
{EDFFDA74-090D-439C-A58D-06CCF86D4423} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
14631487
{C6D6D878-208A-4FD2-822E-365545D8681B} = {447C8A77-E5F0-4538-8687-7383196D04EA}
1488+
{9DD41C8F-0886-483C-B98B-C55EAA7F226D} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
1489+
{0AD06E14-CBFE-4551-8D18-9E921D8F2A87} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
1490+
{08531C5D-0436-4721-986D-96446CF54316} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
1491+
{0CFC9D4F-F12F-4B44-ABCF-AB4A0E9E85B2} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
14641492
{192A829F-D608-4E41-8DE0-058E943E453F} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
14651493
{DCC41E99-EBC7-4F19-BA0D-A6F770D8E431} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
14661494
{18B796D2-D45D-41AE-9A42-75C9B14B20DF} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2+
<ConfigureAwait ContinueOnCapturedContext="false" />
3+
</Weavers>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
4+
<xs:element name="Weavers">
5+
<xs:complexType>
6+
<xs:all>
7+
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
8+
<xs:complexType>
9+
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
10+
</xs:complexType>
11+
</xs:element>
12+
</xs:all>
13+
<xs:attribute name="VerifyAssembly" type="xs:boolean">
14+
<xs:annotation>
15+
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
16+
</xs:annotation>
17+
</xs:attribute>
18+
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
19+
<xs:annotation>
20+
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
21+
</xs:annotation>
22+
</xs:attribute>
23+
<xs:attribute name="GenerateXsd" type="xs:boolean">
24+
<xs:annotation>
25+
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
26+
</xs:annotation>
27+
</xs:attribute>
28+
</xs:complexType>
29+
</xs:element>
30+
</xs:schema>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<Import Project="..\..\..\configureawait.props" />
4+
<Import Project="..\..\..\common.props" />
5+
6+
<PropertyGroup>
7+
<TargetFramework>net7.0</TargetFramework>
8+
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
9+
<AssemblyName>Volo.Abp.AspNetCore.Mvc.NewtonsoftJson</AssemblyName>
10+
<PackageId>Volo.Abp.AspNetCore.Mvc.NewtonsoftJson</PackageId>
11+
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
12+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
13+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
14+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
15+
<IsPackable>true</IsPackable>
16+
<OutputType>Library</OutputType>
17+
<RootNamespace />
18+
</PropertyGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" />
22+
<ProjectReference Include="..\Volo.Abp.Json.Newtonsoft\Volo.Abp.Json.Newtonsoft.csproj" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="$(MicrosoftAspNetCorePackageVersion)" />
27+
</ItemGroup>
28+
29+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Volo.Abp.Json.Newtonsoft;
4+
using Volo.Abp.Modularity;
5+
6+
namespace Volo.Abp.AspNetCore.Mvc.NewtonsoftJson;
7+
8+
[DependsOn(typeof(AbpJsonNewtonsoftModule), typeof(AbpAspNetCoreMvcModule))]
9+
public class AbpAspNetCoreMvcNewtonsoftModule : AbpModule
10+
{
11+
public override void ConfigureServices(ServiceConfigurationContext context)
12+
{
13+
context.Services.AddMvcCore().AddNewtonsoftJson();
14+
15+
context.Services.AddOptions<MvcNewtonsoftJsonOptions>()
16+
.Configure<AbpCamelCasePropertyNamesContractResolver>((options, contractResolver) =>
17+
{
18+
options.SerializerSettings.ContractResolver = contractResolver;
19+
});
20+
}
21+
}

framework/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
<ItemGroup>
3131
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="$(MicrosoftAspNetCorePackageVersion)" />
32-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="$(MicrosoftAspNetCorePackageVersion)" />
3332
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
3433
</ItemGroup>
3534

framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
using Volo.Abp.Http.Modeling;
3939
using Volo.Abp.Http.ProxyScripting.Generators.JQuery;
4040
using Volo.Abp.Json;
41+
using Volo.Abp.Json.SystemTextJson;
4142
using Volo.Abp.Localization;
4243
using Volo.Abp.Modularity;
4344
using Volo.Abp.UI;
@@ -52,7 +53,8 @@ namespace Volo.Abp.AspNetCore.Mvc;
5253
typeof(AbpAspNetCoreMvcContractsModule),
5354
typeof(AbpUiNavigationModule),
5455
typeof(AbpGlobalFeaturesModule),
55-
typeof(AbpDddApplicationModule)
56+
typeof(AbpDddApplicationModule),
57+
typeof(AbpJsonSystemTextJsonModule)
5658
)]
5759
public class AbpAspNetCoreMvcModule : AbpModule
5860
{
@@ -145,7 +147,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
145147
mvcCoreBuilder.AddAbpRazorRuntimeCompilation();
146148
}
147149

148-
mvcCoreBuilder.AddAbpHybridJson();
150+
mvcCoreBuilder.AddAbpJson();
149151

150152
context.Services.ExecutePreConfiguredActions(mvcBuilder);
151153

framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProviderOptions.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,12 @@ public AspNetCoreApiDescriptionModelProviderOptions()
6262
{
6363
if (apiParameterDescription.ModelMetadata is DefaultModelMetadata defaultModelMetadata)
6464
{
65-
var jsonPropertyNameAttribute = (System.Text.Json.Serialization.JsonPropertyNameAttribute)
66-
defaultModelMetadata?.Attributes?.PropertyAttributes?.FirstOrDefault(x => x is System.Text.Json.Serialization.JsonPropertyNameAttribute);
65+
var jsonPropertyNameAttribute = (JsonPropertyNameAttribute)
66+
defaultModelMetadata?.Attributes?.PropertyAttributes?.FirstOrDefault(x => x is JsonPropertyNameAttribute);
6767
if (jsonPropertyNameAttribute != null)
6868
{
6969
return jsonPropertyNameAttribute.Name;
7070
}
71-
72-
var jsonPropertyAttribute = (Newtonsoft.Json.JsonPropertyAttribute)
73-
defaultModelMetadata?.Attributes?.PropertyAttributes?.FirstOrDefault(x => x is Newtonsoft.Json.JsonPropertyAttribute);
74-
if (jsonPropertyAttribute != null)
75-
{
76-
return jsonPropertyAttribute.PropertyName;
77-
}
7871
}
7972

8073
return null;

framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOptionsSetup.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)