refactor: 注解与宏改名——Serializer 前缀统一命名

- @JsonPropertyName → @SerializerPropertyName
- @JsonIgnore → @SerializerIgnore
- @JsonParent → @SerializerParent(宏文件 JsonParentMacro.cj → SerializerParentMacro.cj)
- 同步更新:JsonAnnotations、ReflectionCache、宏内部注解判断、
  测试、方案文档、serialization_test 独立项目
- 16 用例全绿
This commit is contained in:
2026-08-17 13:58:05 +08:00
parent affadac6c2
commit 990f10f98c
9 changed files with 77 additions and 77 deletions
+11 -11
View File
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2025 SimcuTeam. All rights reserved.
* ReflectionCache:字段元数据(含继承链、命名策略、@JsonPropertyName/@JsonIgnore)与缓存。
* ReflectionCache:字段元数据(含继承链、命名策略、@SerializerPropertyName/@SerializerIgnore)与缓存。
*
* 已知限制(平台级):
* - InstanceVariableInfo.getValue/setValue 有「声明类严格类型校验」,父类字段无法用子类实例读写,
@@ -18,9 +18,9 @@ import std.reflect.*
public class FieldMetadata {
/// 反射字段名(如 _name
public var name: String = ""
/// JSON 名称(@JsonPropertyName 优先,否则按命名策略)
/// JSON 名称(@SerializerPropertyName 优先,否则按命名策略)
public var jsonName: String = ""
/// 是否忽略(@JsonIgnore
/// 是否忽略(@SerializerIgnore
public var ignore: Bool = false
/// 字段类型
public var typeInfo: ?TypeInfo = None
@@ -40,20 +40,20 @@ public class ReflectionCache {
private static let _cache = HashMap<String, ArrayList<FieldMetadata>>()
/// 类型 → 是否有 @JsonParent 宏生成的 exportJsonFieldsBool
/// 类型 → 是否有 @SerializerParent 宏生成的 exportJsonFieldsBool
private static let _exportCache = HashMap<String, Bool>()
/// 类型 → 是否有 @JsonParent 宏生成的 importJsonFieldsBool
/// 类型 → 是否有 @SerializerParent 宏生成的 importJsonFieldsBool
private static let _importCache = HashMap<String, Bool>()
/**
* 该类型是否含 @JsonParent 宏生成的导出静态方法(含缓存)。
* 该类型是否含 @SerializerParent 宏生成的导出静态方法(含缓存)。
*/
public static func hasExportFields(typeInfo: ClassTypeInfo): Bool {
hasParentMethod(typeInfo, "exportJsonFields", _exportCache)
}
/**
* 该类型是否含 @JsonParent 宏生成的导入静态方法(含缓存)。
* 该类型是否含 @SerializerParent 宏生成的导入静态方法(含缓存)。
*/
public static func hasImportFields(typeInfo: ClassTypeInfo): Bool {
hasParentMethod(typeInfo, "importJsonFields", _importCache)
@@ -96,13 +96,13 @@ public class ReflectionCache {
meta.variable = Some(v)
meta.typeInfo = Some(v.typeInfo)
meta.mutable = v.isMutable()
// @JsonIgnore
if (v.findAnnotation<JsonIgnore>().isSome()) {
// @SerializerIgnore
if (v.findAnnotation<SerializerIgnore>().isSome()) {
meta.ignore = true
}
// @JsonPropertyName 优先
// @SerializerPropertyName 优先
var jsonName = ""
if (let Some(jsonProp) <- v.findAnnotation<JsonPropertyName>()) {
if (let Some(jsonProp) <- v.findAnnotation<SerializerPropertyName>()) {
jsonName = jsonProp.name
} else {
jsonName = applyNamingPolicy(v.name, options.propertyNamingPolicy)