登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
代码拉取完成,页面将自动刷新
开源项目
>
WEB应用开发
>
Web开发框架
&&
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
10.1K
Star
14.5K
Fork
4.2K
GVP
dotNET China
/
Furion
代码
Issues
0
Pull Requests
0
统计
流水线
服务
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
开发画像分析
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
Http远程请求序列化异常,设置枚举序列化策略为CamelCase,同样的配置在字符串序列化时可以正常使用,但是远程请求报错
已完成
#IK5MUW
曹y
创建于
2026-07-31 16:39
### 版本号 4.9.9.47 ### .NET SDK .NET10 ### 项目类型 WebApi ### 操作系统 Windows 10 ### 运行环境 开发环境 (Development) ### 数据库类型 MySql 8+ ### 应用托管程序 Kestrel ### 这个问题是否已经存在? - [x] 我已经搜索过现有的问题 (https://gitee.com/dotnetchina/Furion/issues) ### 如何复现 1.创建一个对象设置其中一个属性为枚举 例如: ```cs public class SysTagInfo { /// <summary> /// 标签类型 /// </summary> public TagType Type { get; set; } = default!; /// <summary> /// 主键 /// </summary> public long Id { get; set; } = default!; } public enum TagType { DynamicForm = 0, SystemCode = 1, Custom = 2, } ``` 远程返回数据: ```json { "outputData": { "type": "dynamicForm", "id": "12843684629708869" }, "status": true, "msg": null, "code": 200, "timeSpan": "1785486408880", "traceId": "00-9436e46a0d7dd016e2bc0910c0bc4cff-aeb2e827982d82f0-00" } ```  序列化配置: ```cs /// <summary> /// 获取默认的 Json 序列化选项 /// </summary> public static JsonSerializerOptions Settings { get; } = new JsonSerializerOptions().GetInfraJsonOptions(); /// <summary> /// 全局的 Json 序列化选项 /// </summary> /// <param name="options">The options.</param> /// <param name="isWriteIndented"></param> /// <param name="isIgnoreNull"></param> /// <returns></returns> public static JsonSerializerOptions GetInfraJsonOptions(this JsonSerializerOptions options, bool isWriteIndented = true, bool isIgnoreNull = false) { //自定义序列化转换器 options.Converters.AddObjectTypeConverters(); options.TypeInfoResolverChain.Add(new DefaultJsonTypeInfoResolver { Modifiers = { typeInfo => { foreach (var property in typeInfo.Properties) { if (property.Name.EndsWith("Handle") || property.Name.Equals("Handle", StringComparison.OrdinalIgnoreCase)) { property.ShouldSerialize = (_, _) => false; continue; } var type = property.PropertyType; if (type == typeof(IntPtr) || typeof(WaitHandle).IsAssignableFrom(type) || typeof(SafeHandle).IsAssignableFrom(type)) { property.ShouldSerialize = (_, _) => false; } } } } }); #if false //全局忽略 null 值 options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; #endif //驼峰命名输出 options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; //大小写不敏感 options.PropertyNameCaseInsensitive = true; //忽略Json中不存在的属性 options.UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip; //字典序列化 options.DictionaryKeyPolicy = null; //忽略循环引用 options.ReferenceHandler = ReferenceHandler.IgnoreCycles; //允许从字符串中读取数字 options.NumberHandling = JsonNumberHandling.AllowReadingFromString; //不支持的类型时处理为 JsonNode options.UnknownTypeHandling = JsonUnknownTypeHandling.JsonNode; //包含成员字段序列化 options.IncludeFields = false; //允许注释 options.ReadCommentHandling = JsonCommentHandling.Skip; //处理中文乱码问题 options.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping; //缩进输出 options.WriteIndented = isWriteIndented; return options; } /// <summary> /// 添加其他对象类型转换器 /// </summary> /// <param name="converters">The options.</param> /// <returns></returns> public static IList<JsonConverter> AddObjectTypeConverters(this IList<JsonConverter> converters) { //时间类型转换器 converters.AddDateTimeTypeConverters(); //日期类型转换器 converters.AddDateOnlyConverters(); //TimeOnly类型转换器 converters.AddTimeOnlyConverters(); //long类型转换器 converters.AddLongTypeConverters(); #region Newtonsoft.Json converters.Add(new JObjectTypeConverter()); converters.Add(new NullableJObjectTypeConverter()); converters.Add(new JArrayTypeConverter()); converters.Add(new NullableJArrayTypeConverter()); converters.Add(new JTokenTypeConverter()); converters.Add(new NullableJTokenTypeConverter()); #endregion converters.Add(new SafeExceptionConverter()); // 枚举序列化 converters.Add(new JsonStringEnumConverter(namingPolicy: JsonNamingPolicy.CamelCase, allowIntegerValues: true)); #if false // number、boolean 转 string converters.Add(new StringJsonConverter()); #endif return converters; } ``` ### 预期结果 正常徐磊话 ### 实际结果 没有识别或者没有使用我自定义的序列化配置 ### 异常信息 ``` System.Text.Json.JsonException: The JSON value could not be converted to Cams.Basic.Info.HttpProxy.Dtos.TagType. Path: $.outputData.type | LineNumber: 5 | BytePositionInLine: 25. ``` ### 截图或视频  ### Demo 地址(Git/网盘/SVN)| 未提供则视为无效 `Issue` 暂无 ### 友好承诺 - [x] 我承诺将本着相互尊重、理解和友善的态度进行交流,共同维护好 Furion 来之不易的良好的社区氛围。 ### 提交前请确认 - [x] 我已附上可复现问题的最小化代码示例或在线 Demo 链接。**请注意:未提供复现 Demo 的 `Issue` 可能无法得到回复或会被关闭。**
### 版本号 4.9.9.47 ### .NET SDK .NET10 ### 项目类型 WebApi ### 操作系统 Windows 10 ### 运行环境 开发环境 (Development) ### 数据库类型 MySql 8+ ### 应用托管程序 Kestrel ### 这个问题是否已经存在? - [x] 我已经搜索过现有的问题 (https://gitee.com/dotnetchina/Furion/issues) ### 如何复现 1.创建一个对象设置其中一个属性为枚举 例如: ```cs public class SysTagInfo { /// <summary> /// 标签类型 /// </summary> public TagType Type { get; set; } = default!; /// <summary> /// 主键 /// </summary> public long Id { get; set; } = default!; } public enum TagType { DynamicForm = 0, SystemCode = 1, Custom = 2, } ``` 远程返回数据: ```json { "outputData": { "type": "dynamicForm", "id": "12843684629708869" }, "status": true, "msg": null, "code": 200, "timeSpan": "1785486408880", "traceId": "00-9436e46a0d7dd016e2bc0910c0bc4cff-aeb2e827982d82f0-00" } ```  序列化配置: ```cs /// <summary> /// 获取默认的 Json 序列化选项 /// </summary> public static JsonSerializerOptions Settings { get; } = new JsonSerializerOptions().GetInfraJsonOptions(); /// <summary> /// 全局的 Json 序列化选项 /// </summary> /// <param name="options">The options.</param> /// <param name="isWriteIndented"></param> /// <param name="isIgnoreNull"></param> /// <returns></returns> public static JsonSerializerOptions GetInfraJsonOptions(this JsonSerializerOptions options, bool isWriteIndented = true, bool isIgnoreNull = false) { //自定义序列化转换器 options.Converters.AddObjectTypeConverters(); options.TypeInfoResolverChain.Add(new DefaultJsonTypeInfoResolver { Modifiers = { typeInfo => { foreach (var property in typeInfo.Properties) { if (property.Name.EndsWith("Handle") || property.Name.Equals("Handle", StringComparison.OrdinalIgnoreCase)) { property.ShouldSerialize = (_, _) => false; continue; } var type = property.PropertyType; if (type == typeof(IntPtr) || typeof(WaitHandle).IsAssignableFrom(type) || typeof(SafeHandle).IsAssignableFrom(type)) { property.ShouldSerialize = (_, _) => false; } } } } }); #if false //全局忽略 null 值 options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; #endif //驼峰命名输出 options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; //大小写不敏感 options.PropertyNameCaseInsensitive = true; //忽略Json中不存在的属性 options.UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip; //字典序列化 options.DictionaryKeyPolicy = null; //忽略循环引用 options.ReferenceHandler = ReferenceHandler.IgnoreCycles; //允许从字符串中读取数字 options.NumberHandling = JsonNumberHandling.AllowReadingFromString; //不支持的类型时处理为 JsonNode options.UnknownTypeHandling = JsonUnknownTypeHandling.JsonNode; //包含成员字段序列化 options.IncludeFields = false; //允许注释 options.ReadCommentHandling = JsonCommentHandling.Skip; //处理中文乱码问题 options.Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping; //缩进输出 options.WriteIndented = isWriteIndented; return options; } /// <summary> /// 添加其他对象类型转换器 /// </summary> /// <param name="converters">The options.</param> /// <returns></returns> public static IList<JsonConverter> AddObjectTypeConverters(this IList<JsonConverter> converters) { //时间类型转换器 converters.AddDateTimeTypeConverters(); //日期类型转换器 converters.AddDateOnlyConverters(); //TimeOnly类型转换器 converters.AddTimeOnlyConverters(); //long类型转换器 converters.AddLongTypeConverters(); #region Newtonsoft.Json converters.Add(new JObjectTypeConverter()); converters.Add(new NullableJObjectTypeConverter()); converters.Add(new JArrayTypeConverter()); converters.Add(new NullableJArrayTypeConverter()); converters.Add(new JTokenTypeConverter()); converters.Add(new NullableJTokenTypeConverter()); #endregion converters.Add(new SafeExceptionConverter()); // 枚举序列化 converters.Add(new JsonStringEnumConverter(namingPolicy: JsonNamingPolicy.CamelCase, allowIntegerValues: true)); #if false // number、boolean 转 string converters.Add(new StringJsonConverter()); #endif return converters; } ``` ### 预期结果 正常徐磊话 ### 实际结果 没有识别或者没有使用我自定义的序列化配置 ### 异常信息 ``` System.Text.Json.JsonException: The JSON value could not be converted to Cams.Basic.Info.HttpProxy.Dtos.TagType. Path: $.outputData.type | LineNumber: 5 | BytePositionInLine: 25. ``` ### 截图或视频  ### Demo 地址(Git/网盘/SVN)| 未提供则视为无效 `Issue` 暂无 ### 友好承诺 - [x] 我承诺将本着相互尊重、理解和友善的态度进行交流,共同维护好 Furion 来之不易的良好的社区氛围。 ### 提交前请确认 - [x] 我已附上可复现问题的最小化代码示例或在线 Demo 链接。**请注意:未提供复现 Demo 的 `Issue` 可能无法得到回复或会被关闭。**
评论 (
3
)
登录
后才可以发表评论
状态
已完成
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (
-
)
标签 (
-
)
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(2)
C#
1
https://gitee.com/dotnetchina/Furion.git
git@gitee.com:dotnetchina/Furion.git
dotnetchina
Furion
Furion
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册