perf(#I12XQJ): 移除 Json.net 全面使用 System.Text.Json

#Issue
close #I12XQJ
This commit is contained in:
Argo Zhang 2019-10-03 10:44:32 +08:00
parent 77e1b847da
commit 0b69f5d51d
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
5 changed files with 19 additions and 29 deletions

View File

@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
<PropertyGroup>
<DocumentationFile>$(MSBuildProjectName).xml</DocumentationFile>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
@ -13,16 +13,12 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.1-beta5" />
<PackageReference Include="Longbow" Version="3.0.0-beta1" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Logging" Version="3.0.0" />
<PackageReference Include="Longbow.Tasks" Version="2.2.24" />
<PackageReference Include="Longbow.Web" Version="3.0.0-beta1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Sentry.AspNetCore" Version="2.0.0-beta4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
<PackageReference Include="System.Data.SqlClient" Version="4.7.0" />

View File

@ -11,8 +11,6 @@ using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Text.Encodings.Web;
using System.Text.Unicode;
@ -59,11 +57,7 @@ namespace Bootstrap.Admin
services.AddDbAdapter();
services.AddIPLocator(DictHelper.ConfigIPLocator);
services.AddOnlineUsers();
services.AddSignalR().AddNewtonsoftJsonProtocol(op =>
{
op.PayloadSerializerSettings.ContractResolver = new DefaultContractResolver();
op.PayloadSerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
});
services.AddSignalR().AddJsonProtocol(op => op.PayloadSerializerOptions.Configure());
services.AddSignalRExceptionFilterHandler<SignalRHub>(async (client, ex) => await client.SendMessageBody(ex).ConfigureAwait(false));
services.AddResponseCompression();
services.AddBootstrapAdminAuthentication().AddGitee(OAuthHelper.Configure).AddGitHub(OAuthHelper.Configure);
@ -77,12 +71,7 @@ namespace Bootstrap.Admin
{
options.Filters.Add<ExceptionFilter>();
options.Filters.Add<SignalRExceptionFilter<SignalRHub>>();
}).AddNewtonsoftJson(op =>
{
op.SerializerSettings.ContractResolver = new DefaultContractResolver();
op.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
JsonConvert.DefaultSettings = () => op.SerializerSettings;
});
}).AddJsonOptions(op => op.JsonSerializerOptions.Configure());
services.AddApiVersioning(option =>
{
option.DefaultApiVersion = new ApiVersion(1, 0);

View File

@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
<PackageReference Include="Longbow" Version="3.0.0-beta1" />
<PackageReference Include="Longbow" Version="3.0.0-beta2" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Data" Version="2.3.8" />
<PackageReference Include="Longbow.GiteeAuth" Version="2.2.0" />

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.WebUtilities;
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@ -8,6 +7,12 @@ using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
#if NETCOREAPP3_0
using System.Text.Json;
#else
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
#endif
namespace Bootstrap.DataAccess
{
@ -38,7 +43,14 @@ namespace Bootstrap.DataAccess
var url = QueryHelpers.AddQueryString("http://open.bluegoon.com/api/sms/sendcode", requestParameters);
var req = await client.GetAsync(url);
var content = await req.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<SMSResult>(content);
#if NETCOREAPP3_0
var result = JsonSerializer.Deserialize<SMSResult>(content, new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true
});
#else
var result = JsonConvert.DeserializeObject<SMSResult>(content, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
#endif
var ret = false;
if (result.Code == "1")
{

View File

@ -9,8 +9,6 @@ using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
namespace Bootstrap.Client
@ -62,12 +60,7 @@ namespace Bootstrap.Client
{
options.Filters.Add<ExceptionFilter>();
options.Filters.Add<SignalRExceptionFilter<SignalRHub>>();
}).AddNewtonsoftJson(op =>
{
op.SerializerSettings.ContractResolver = new DefaultContractResolver();
op.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
JsonConvert.DefaultSettings = () => op.SerializerSettings;
});
}).AddJsonOptions(op => op.JsonSerializerOptions.Configure());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.