😎优化调整序列化配置项
This commit is contained in:
parent
6e3ab0491f
commit
e5b6cc2fba
@ -52,7 +52,7 @@
|
|||||||
<PackageReference Include="SixLabors.ImageSharp.Web" Version="3.1.5" />
|
<PackageReference Include="SixLabors.ImageSharp.Web" Version="3.1.5" />
|
||||||
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="3.11.0" />
|
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="3.11.0" />
|
||||||
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="3.13.0" />
|
<PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="3.13.0" />
|
||||||
<PackageReference Include="SqlSugar.MongoDbCore" Version="5.1.4.235" />
|
<PackageReference Include="SqlSugar.MongoDbCore" Version="5.1.4.236" />
|
||||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.198" />
|
<PackageReference Include="SqlSugarCore" Version="5.1.4.198" />
|
||||||
<PackageReference Include="SSH.NET" Version="2025.0.0" />
|
<PackageReference Include="SSH.NET" Version="2025.0.0" />
|
||||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.7" />
|
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.7" />
|
||||||
|
|||||||
@ -24,15 +24,19 @@ using Microsoft.Extensions.FileProviders;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using MQTTnet.AspNetCore;
|
using MQTTnet.AspNetCore;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
using OnceMi.AspNetCore.OSS;
|
using OnceMi.AspNetCore.OSS;
|
||||||
using RabbitMQ.Client;
|
using RabbitMQ.Client;
|
||||||
using SixLabors.ImageSharp.Web.DependencyInjection;
|
using SixLabors.ImageSharp.Web.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.Unicode;
|
using System.Text.Unicode;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -48,6 +52,7 @@ public class Startup : AppStartup
|
|||||||
|
|
||||||
// 缓存注册
|
// 缓存注册
|
||||||
services.AddCache();
|
services.AddCache();
|
||||||
|
|
||||||
// JWT
|
// JWT
|
||||||
services.AddJwt<JwtHandler>(enableGlobalAuthorize: true, jwtBearerConfigure: options =>
|
services.AddJwt<JwtHandler>(enableGlobalAuthorize: true, jwtBearerConfigure: options =>
|
||||||
{
|
{
|
||||||
@ -74,8 +79,10 @@ public class Startup : AppStartup
|
|||||||
|
|
||||||
// 允许跨域
|
// 允许跨域
|
||||||
services.AddCorsAccessor();
|
services.AddCorsAccessor();
|
||||||
|
|
||||||
// 远程请求
|
// 远程请求
|
||||||
services.AddHttpRemote();
|
services.AddHttpRemote();
|
||||||
|
|
||||||
// 任务队列
|
// 任务队列
|
||||||
services.AddTaskQueue(builder =>
|
services.AddTaskQueue(builder =>
|
||||||
{
|
{
|
||||||
@ -88,6 +95,7 @@ public class Startup : AppStartup
|
|||||||
Log.Error($"任务队列异常:{args.Exception?.Message}", args.Exception);
|
Log.Error($"任务队列异常:{args.Exception?.Message}", args.Exception);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// 作业调度
|
// 作业调度
|
||||||
services.AddSchedule(options =>
|
services.AddSchedule(options =>
|
||||||
{
|
{
|
||||||
@ -103,29 +111,11 @@ public class Startup : AppStartup
|
|||||||
//};
|
//};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 脱敏检测
|
// 脱敏检测
|
||||||
services.AddSensitiveDetection();
|
services.AddSensitiveDetection();
|
||||||
|
|
||||||
// Json序列化设置
|
// 动态 WebAPI
|
||||||
static void SetNewtonsoftJsonSetting(JsonSerializerSettings setting)
|
|
||||||
{
|
|
||||||
setting.DateFormatHandling = DateFormatHandling.IsoDateFormat;
|
|
||||||
setting.DateTimeZoneHandling = DateTimeZoneHandling.Local;
|
|
||||||
//setting.Converters.AddDateTimeTypeConverters(localized: true); // 时间本地化
|
|
||||||
setting.DateFormatString = "yyyy-MM-dd HH:mm:ss"; // 时间格式化
|
|
||||||
setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // 忽略循环引用
|
|
||||||
// setting.ContractResolver = new CamelCasePropertyNamesContractResolver(); // 解决动态对象属性名大写
|
|
||||||
// setting.NullValueHandling = NullValueHandling.Ignore; // 忽略空值
|
|
||||||
// setting.Converters.AddLongTypeConverters(); // long转string(防止js精度溢出) 超过17位开启
|
|
||||||
// setting.MetadataPropertyHandling = MetadataPropertyHandling.Ignore; // 解决DateTimeOffset异常
|
|
||||||
// setting.DateParseHandling = DateParseHandling.None; // 解决DateTimeOffset异常
|
|
||||||
//setting.Converters.Add(new IsoDateTimeConverter
|
|
||||||
//{
|
|
||||||
// DateTimeFormat = "yyyy-MM-dd HH:mm:ss", // 时间格式
|
|
||||||
// DateTimeStyles = DateTimeStyles.AssumeLocal | DateTimeStyles.AdjustToUniversal
|
|
||||||
//}); // 解决DateTimeOffset异常
|
|
||||||
}
|
|
||||||
|
|
||||||
services.AddControllersWithViews()
|
services.AddControllersWithViews()
|
||||||
.AddAppLocalization(settings => { services.AddJsonLocalization(options => options.ResourcesPath = settings.ResourcesPath); }) // 集成第三方多语言配置
|
.AddAppLocalization(settings => { services.AddJsonLocalization(options => options.ResourcesPath = settings.ResourcesPath); }) // 集成第三方多语言配置
|
||||||
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
|
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
|
||||||
@ -134,10 +124,46 @@ public class Startup : AppStartup
|
|||||||
.AddInjectWithUnifyResult<AdminNETResultProvider>()
|
.AddInjectWithUnifyResult<AdminNETResultProvider>()
|
||||||
.AddJsonOptions(options =>
|
.AddJsonOptions(options =>
|
||||||
{
|
{
|
||||||
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); // 禁止Unicode转码
|
//options.JsonSerializerOptions.PropertyNamingPolicy = null; // 序列化属性名大写(属性原样输出)
|
||||||
//options.JsonSerializerOptions.Converters.AddDateTimeTypeConverters("yyyy-MM-dd HH:mm:ss", localized: true); // 时间格式
|
options.JsonSerializerOptions.Converters.AddDateTimeTypeConverters("yyyy-MM-dd HH:mm:ss", localized: true); // 时间格式化
|
||||||
|
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; // 忽略循环引用
|
||||||
|
options.JsonSerializerOptions.IncludeFields = true; // 包含成员字段序列化
|
||||||
|
options.JsonSerializerOptions.AllowTrailingCommas = true; // 允许尾随逗号
|
||||||
|
options.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip; // 允许注释
|
||||||
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); // 禁止 Unicode 转码
|
||||||
|
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping; // 处理(中文)乱码问题
|
||||||
|
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; // 不区分大小写
|
||||||
|
//options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; // 忽略所有 null 属性
|
||||||
|
//options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault; // 忽略所有默认值属性
|
||||||
|
options.JsonSerializerOptions.WriteIndented = true; // JSON 字符串缩进
|
||||||
|
options.JsonSerializerOptions.Converters.AddLongTypeConverters(overMaxLengthOf17: true); // long 类型序列化时转 string(超过 17 位再转换)
|
||||||
|
//options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString; // String 转 Number
|
||||||
|
//options.JsonSerializerOptions.Converters.Add(new StringJsonConverter()); // Number 和 Boolean 转 String
|
||||||
|
options.JsonSerializerOptions.Converters.AddDateOnlyConverters(); // DateOnly
|
||||||
|
options.JsonSerializerOptions.Converters.AddTimeOnlyConverters(); // TimeOnly
|
||||||
|
options.JsonSerializerOptions.Converters.AddClayConverters(); // 粘土对象 Clay 类型序列化支持
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// NewtonsoftJson 序列化设置
|
||||||
|
static void SetNewtonsoftJsonSetting(JsonSerializerSettings setting)
|
||||||
|
{
|
||||||
|
//setting.ContractResolver = new DefaultContractResolver(); // 序列化属性名大写(属性原样输出)
|
||||||
|
setting.Converters.AddDateTimeTypeConverters("yyyy-MM-dd HH:mm:ss", localized: true); // 时间格式化
|
||||||
|
setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // 忽略循环引用
|
||||||
|
//setting.NullValueHandling = NullValueHandling.Ignore; // 忽略所有 null 属性
|
||||||
|
//setting.DefaultValueHandling = DefaultValueHandling.Ignore; // 忽略所有默认值属性
|
||||||
|
setting.ContractResolver = new CamelCasePropertyNamesContractResolver(); // 解决动态对象属性名大写问题
|
||||||
|
setting.Formatting = Formatting.Indented; // JSON 字符串缩进
|
||||||
|
setting.Converters.AddLongTypeConverters(overMaxLengthOf17: true); // long 类型序列化时转 string(超过 17 位再转换)
|
||||||
|
setting.Converters.AddDateOnlyConverters(); // DateOnly
|
||||||
|
setting.Converters.AddTimeOnlyConverters(); // TimeOnly
|
||||||
|
setting.Converters.AddClayConverters(); // 粘土对象 Clay 类型序列化支持
|
||||||
|
// DateTimeOffset 反序列化异常
|
||||||
|
setting.MetadataPropertyHandling = MetadataPropertyHandling.Ignore;
|
||||||
|
setting.DateParseHandling = DateParseHandling.None;
|
||||||
|
setting.Converters.Add(new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal });
|
||||||
|
}
|
||||||
|
|
||||||
// 增加字典Key小写处理序列化配置选项
|
// 增加字典Key小写处理序列化配置选项
|
||||||
var camelCaseDictionaryKeyContractJsonSetting = new JsonSerializerSettings();
|
var camelCaseDictionaryKeyContractJsonSetting = new JsonSerializerSettings();
|
||||||
SetNewtonsoftJsonSetting(camelCaseDictionaryKeyContractJsonSetting);
|
SetNewtonsoftJsonSetting(camelCaseDictionaryKeyContractJsonSetting);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "admin.net.pro",
|
"name": "admin.net.pro",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "2.4.33",
|
"version": "2.4.33",
|
||||||
"lastBuildTime": "2025.07.29",
|
"lastBuildTime": "2025.07.31",
|
||||||
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
|
"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
|
||||||
"author": "zuohuaijun",
|
"author": "zuohuaijun",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -35,7 +35,7 @@
|
|||||||
"countup.js": "^2.9.0",
|
"countup.js": "^2.9.0",
|
||||||
"cropperjs": "^1.6.2",
|
"cropperjs": "^1.6.2",
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"echarts": "^5.6.0",
|
"echarts": "^6.0.0",
|
||||||
"echarts-gl": "^2.0.9",
|
"echarts-gl": "^2.0.9",
|
||||||
"echarts-wordcloud": "^2.1.0",
|
"echarts-wordcloud": "^2.1.0",
|
||||||
"element-plus": "^2.10.4",
|
"element-plus": "^2.10.4",
|
||||||
@ -53,7 +53,7 @@
|
|||||||
"md-editor-v3": "^5.8.3",
|
"md-editor-v3": "^5.8.3",
|
||||||
"mitt": "^3.0.1",
|
"mitt": "^3.0.1",
|
||||||
"monaco-editor": "^0.52.2",
|
"monaco-editor": "^0.52.2",
|
||||||
"mqtt": "^5.13.3",
|
"mqtt": "^5.14.0",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"ol": "^10.6.1",
|
"ol": "^10.6.1",
|
||||||
"pinia": "^3.0.3",
|
"pinia": "^3.0.3",
|
||||||
@ -82,7 +82,7 @@
|
|||||||
"vue-router": "^4.5.1",
|
"vue-router": "^4.5.1",
|
||||||
"vue-signature-pad": "^3.0.2",
|
"vue-signature-pad": "^3.0.2",
|
||||||
"vue3-tree-org": "^4.2.2",
|
"vue3-tree-org": "^4.2.2",
|
||||||
"vxe-pc-ui": "^4.8.0",
|
"vxe-pc-ui": "^4.8.2",
|
||||||
"vxe-table": "^4.14.8",
|
"vxe-table": "^4.14.8",
|
||||||
"xe-utils": "^3.7.8",
|
"xe-utils": "^3.7.8",
|
||||||
"xlsx-js-style": "^1.2.0"
|
"xlsx-js-style": "^1.2.0"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user