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

@@ -25,9 +25,15 @@ import java.util.Objects;
@Slf4j
public class SensitiveHandler extends JsonSerializer<String> implements ContextualSerializer {
private SensitiveStrategy strategy;
private String[] roleKey;
private String[] perms;
private final SensitiveStrategy strategy;
private final String[] roleKey;
private final String[] perms;
public SensitiveHandler(SensitiveStrategy strategy, String[] strings, String[] perms) {
this.strategy = strategy;
this.roleKey = strings;
this.perms = perms;
}
@Override
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
@@ -48,10 +54,7 @@ public class SensitiveHandler extends JsonSerializer<String> implements Contextu
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
Sensitive annotation = property.getAnnotation(Sensitive.class);
if (Objects.nonNull(annotation) && Objects.equals(String.class, property.getType().getRawClass())) {
this.strategy = annotation.strategy();
this.roleKey = annotation.roleKey();
this.perms = annotation.perms();
return this;
return new SensitiveHandler(annotation.strategy(), annotation.roleKey(), annotation.perms());
}
return prov.findValueSerializer(property.getType(), property);
}