fix(multilingual): bind fields through generic response wrappers
Run multilingual backfill before the global return handler and traverse Object-typed fields by runtime type, so @MultilingualField still works when the body is wrapped in TimiResponse.
This commit is contained in:
@@ -341,6 +341,10 @@ public class MultilingualFieldBinder {
|
||||
}
|
||||
|
||||
private boolean isSimpleValueType(Class<?> clazz) {
|
||||
// 泛型字段在反射中表现为 Object,实际值仍需按运行时类型继续遍历
|
||||
if (Object.class == clazz) {
|
||||
return false;
|
||||
}
|
||||
if (clazz.isPrimitive() || clazz.isEnum() || clazz.isAnnotation()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.imyeyu.api.util;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
@@ -14,11 +16,15 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
/**
|
||||
* 统一处理响应中的多语言字段回填
|
||||
*
|
||||
* <p>必须在全局返回包装处理器之前执行,否则响应体已被包装为 TimiResponse,
|
||||
* 其 {@code data} 字段声明为泛型 {@code T}(反射类型为 Object),无法继续向下遍历。</p>
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2026-07-17 00:00
|
||||
*/
|
||||
@Component
|
||||
@RestControllerAdvice
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
@RequiredArgsConstructor
|
||||
public class MultilingualResponseBodyAdvice implements ResponseBodyAdvice<Object> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user