update 增加多个方法的注释以提升代码可读性

This commit is contained in:
AprilWind
2026-05-15 13:04:30 +08:00
parent 592d998e0f
commit 4fdf2ea75a
25 changed files with 514 additions and 6 deletions
@@ -16,15 +16,33 @@ public class JsonEnhancementContext {
private final Map<String, Object> attributes = new LinkedHashMap<>();
/**
* 构造响应增强上下文。
*
* @param jsonMapper JSON 映射器
*/
public JsonEnhancementContext(JsonMapper jsonMapper) {
this.jsonMapper = jsonMapper;
}
/**
* 获取上下文属性。
*
* @param key 属性键
* @param <T> 属性值类型
* @return 属性值
*/
@SuppressWarnings("unchecked")
public <T> T getAttribute(String key) {
return (T) attributes.get(key);
}
/**
* 设置上下文属性。
*
* @param key 属性键
* @param value 属性值
*/
public void setAttribute(String key, Object value) {
attributes.put(key, value);
}
@@ -9,6 +9,13 @@ import java.lang.annotation.Annotation;
*/
public record JsonFieldContext(Object owner, String propertyName, AnnotatedMember member, Object value) {
/**
* 获取字段上的指定注解。
*
* @param annotationType 注解类型
* @param <A> 注解类型
* @return 注解对象
*/
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
return member == null ? null : member.getAnnotation(annotationType);
}
@@ -31,6 +31,12 @@ public class JsonValueEnhancer {
private final Map<Class<?>, List<PropertyMetadata>> propertyCache = new ConcurrentHashMap<>();
/**
* 构造统一响应增强器。
*
* @param jsonMapper JSON 映射器
* @param processors 字段处理器列表
*/
public JsonValueEnhancer(JsonMapper jsonMapper, List<JsonFieldProcessor> processors) {
this.jsonMapper = jsonMapper;
List<JsonFieldProcessor> sortedProcessors = new ArrayList<>(processors);
@@ -38,6 +44,12 @@ public class JsonValueEnhancer {
this.processors = Collections.unmodifiableList(sortedProcessors);
}
/**
* 增强响应对象。
*
* @param body 响应对象
* @return 增强后的响应对象
*/
public Object enhance(Object body) {
if (body == null || body instanceof JsonNode || processors.isEmpty()) {
return body;
@@ -45,6 +57,12 @@ public class JsonValueEnhancer {
return enhanceTree(body);
}
/**
* 判断消息转换器是否支持响应增强。
*
* @param converterType 消息转换器类型
* @return true 支持 false 不支持
*/
public boolean supports(Class<?> converterType) {
return !processors.isEmpty()
&& !ByteArrayHttpMessageConverter.class.isAssignableFrom(converterType)