feat: 新增 TypeInfo 版反序列化入口——按运行时类型反序列化
- JsonSerializer.Deserialize(typeInfo, jsonString[, options]): Any - JsonReader.read(typeInfo, value, options): Any - 供框架运行时模型绑定等场景使用(无需编译期泛型)
This commit is contained in:
@@ -30,6 +30,17 @@ public class JsonReader {
|
||||
throw Exception("JsonSerializer: 反序列化结果类型不匹配")
|
||||
}
|
||||
|
||||
/**
|
||||
* 按运行时类型信息反序列化(供框架运行时绑定等场景使用,无需编译期泛型)。
|
||||
* @param typeInfo 目标类型(运行时)。
|
||||
* @param value JSON 值。
|
||||
* @param options 序列化选项。
|
||||
* @return 反序列化后的实例(Any)。
|
||||
*/
|
||||
public static func read(typeInfo: TypeInfo, value: JsonValue, options: JsonOption): Any {
|
||||
readValue(value, typeInfo, options, 0)
|
||||
}
|
||||
|
||||
private static func readValue(value: JsonValue, typeInfo: TypeInfo, options: JsonOption, depth: Int64): Any {
|
||||
if (depth > options.maxDepth) {
|
||||
throw Exception("JsonSerializer: 超过最大递归深度 ${options.maxDepth}")
|
||||
|
||||
Reference in New Issue
Block a user