fix 修复 jackson createContextual 用法不标准导致可能出现的并发问题(https://gitee.com/dromara/RuoYi-Cloud-Plus/issues/IFAM5Z)

This commit is contained in:
疯狂的狮子Li
2026-03-06 16:49:36 +08:00
parent 9bf8ae5583
commit f773818642
2 changed files with 16 additions and 10 deletions

View File

@@ -31,7 +31,11 @@ public class TranslationHandler extends JsonSerializer<Object> implements Contex
*/
public static final Map<String, TranslationInterface<?>> TRANSLATION_MAPPER = new ConcurrentHashMap<>();
private Translation translation;
private final Translation translation;
public TranslationHandler(Translation translation) {
this.translation = translation;
}
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
@@ -63,8 +67,7 @@ public class TranslationHandler extends JsonSerializer<Object> implements Contex
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
Translation translation = property.getAnnotation(Translation.class);
if (Objects.nonNull(translation)) {
this.translation = translation;
return this;
return new TranslationHandler(translation);
}
return prov.findValueSerializer(property.getType(), property);
}