refactor(common-json): 优化 JSON 增强处理链路

- 抽取 JSON 字符串校验的重复解析逻辑
  - 为 JsonFieldProcessor 增加 supports 判断,减少无关字段处理
  - 优化 JsonValueEnhancer,未命中增强字段时直接返回原对象
  - 拆分响应增强渲染逻辑,提升代码可读性
  - 增强上下文属性管理能力
  - 优化翻译、脱敏处理器的字段匹配逻辑
  - 修正 Date 反序列化空字符串处理
  - 支持 LocalDateTime 秒级、毫秒级及负时间戳反序列化
This commit is contained in:
疯狂的狮子Li
2026-05-16 14:08:52 +08:00
parent 7b66f0de26
commit 2af4b2c7a3
8 changed files with 180 additions and 68 deletions
@@ -57,6 +57,17 @@ public class TranslationJsonFieldProcessor implements JsonFieldProcessor {
this.translationMap = Collections.unmodifiableMap(map);
}
/**
* 判断字段是否包含翻译注解。
*
* @param fieldContext 字段上下文
* @return true 需要处理 false 无需处理
*/
@Override
public boolean supports(JsonFieldContext fieldContext) {
return fieldContext.getAnnotation(Translation.class) != null;
}
/**
* 收集字段上的翻译注解和原始值,供后续批量翻译使用。
*
@@ -150,12 +161,7 @@ public class TranslationJsonFieldProcessor implements JsonFieldProcessor {
* @return 待批量翻译数据映射
*/
private Map<TranslationBatchKey, Set<Object>> getOrCreateBatches(JsonEnhancementContext context) {
Map<TranslationBatchKey, Set<Object>> batches = context.getAttribute(ATTR_BATCHES);
if (batches == null) {
batches = new LinkedHashMap<>();
context.setAttribute(ATTR_BATCHES, batches);
}
return batches;
return context.getOrCreateAttribute(ATTR_BATCHES, LinkedHashMap::new);
}
/**