|
|
|
|
@ -99,9 +99,15 @@ namespace Common.Shared.Application.DaHua |
|
|
|
|
{ |
|
|
|
|
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
|
|
|
|
{ |
|
|
|
|
string rawValue = reader.GetString(); |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
string rawValue = reader.TokenType switch |
|
|
|
|
{ |
|
|
|
|
JsonTokenType.String => reader.GetString(), |
|
|
|
|
JsonTokenType.Number => reader.GetInt32().ToString(), // 👈 新增对数值的处理 |
|
|
|
|
_ => throw new JsonException($"无法解析 {typeof(T).Name}:不支持的 JSON 类型 {reader.TokenType}") |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 枚举值可以写成字符串数字形式(例如 "1") |
|
|
|
|
foreach (T enumValue in Enum.GetValues(typeof(T))) |
|
|
|
|
{ |
|
|
|
|
var attr = typeof(T).GetField(enumValue.ToString()) |
|
|
|
|
@ -114,7 +120,12 @@ namespace Common.Shared.Application.DaHua |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
throw new JsonException($"operateType 无效: {rawValue},允许值为 {string.Join(", ", Enum.GetValues(typeof(T)).Cast<T>())}"); |
|
|
|
|
throw new JsonException($"无效的枚举值: {rawValue}"); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
throw new JsonException($"反序列化 {typeof(T).Name} 失败: {ex.Message}", ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) |
|
|
|
|
|