mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-03-08 07:41:09 +08:00
Merge remote-tracking branch 'plus/dev' into dev
This commit is contained in:
@@ -25,9 +25,24 @@ import java.util.Objects;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class SensitiveHandler extends JsonSerializer<String> implements ContextualSerializer {
|
public class SensitiveHandler extends JsonSerializer<String> implements ContextualSerializer {
|
||||||
|
|
||||||
private SensitiveStrategy strategy;
|
private final SensitiveStrategy strategy;
|
||||||
private String[] roleKey;
|
private final String[] roleKey;
|
||||||
private String[] perms;
|
private final String[] perms;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给 jackson 创建上下文序列化器时使用 不然会报错
|
||||||
|
*/
|
||||||
|
public SensitiveHandler() {
|
||||||
|
this.strategy = null;
|
||||||
|
this.roleKey = null;
|
||||||
|
this.perms = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SensitiveHandler(SensitiveStrategy strategy, String[] strings, String[] perms) {
|
||||||
|
this.strategy = strategy;
|
||||||
|
this.roleKey = strings;
|
||||||
|
this.perms = perms;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||||
@@ -48,10 +63,7 @@ public class SensitiveHandler extends JsonSerializer<String> implements Contextu
|
|||||||
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
|
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
|
||||||
Sensitive annotation = property.getAnnotation(Sensitive.class);
|
Sensitive annotation = property.getAnnotation(Sensitive.class);
|
||||||
if (Objects.nonNull(annotation) && Objects.equals(String.class, property.getType().getRawClass())) {
|
if (Objects.nonNull(annotation) && Objects.equals(String.class, property.getType().getRawClass())) {
|
||||||
this.strategy = annotation.strategy();
|
return new SensitiveHandler(annotation.strategy(), annotation.roleKey(), annotation.perms());
|
||||||
this.roleKey = annotation.roleKey();
|
|
||||||
this.perms = annotation.perms();
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
return prov.findValueSerializer(property.getType(), property);
|
return prov.findValueSerializer(property.getType(), property);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,18 @@ public class TranslationHandler extends JsonSerializer<Object> implements Contex
|
|||||||
*/
|
*/
|
||||||
public static final Map<String, TranslationInterface<?>> TRANSLATION_MAPPER = new ConcurrentHashMap<>();
|
public static final Map<String, TranslationInterface<?>> TRANSLATION_MAPPER = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private Translation translation;
|
private final Translation translation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提供给 jackson 创建上下文序列化器时使用 不然会报错
|
||||||
|
*/
|
||||||
|
public TranslationHandler() {
|
||||||
|
this.translation = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TranslationHandler(Translation translation) {
|
||||||
|
this.translation = translation;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||||
@@ -63,8 +74,7 @@ public class TranslationHandler extends JsonSerializer<Object> implements Contex
|
|||||||
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
|
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
|
||||||
Translation translation = property.getAnnotation(Translation.class);
|
Translation translation = property.getAnnotation(Translation.class);
|
||||||
if (Objects.nonNull(translation)) {
|
if (Objects.nonNull(translation)) {
|
||||||
this.translation = translation;
|
return new TranslationHandler(translation);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
return prov.findValueSerializer(property.getType(), property);
|
return prov.findValueSerializer(property.getType(), property);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user