update 增加多个方法的注释以提升代码可读性
This commit is contained in:
+18
@@ -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);
|
||||
}
|
||||
|
||||
+7
@@ -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);
|
||||
}
|
||||
|
||||
+18
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user