疯狂的狮子li
2022-02-11 83c0b70a2d8e67e371b40322f1a8529ca13e3827
ruoyi-common/src/main/java/com/ruoyi/common/jackson/SensitiveJsonSerializer.java
@@ -16,6 +16,7 @@
/**
 * 数据脱敏json序列化工具
 *
 * @author Yjoioooo
 */
public class SensitiveJsonSerializer extends JsonSerializer<String> implements ContextualSerializer {
@@ -25,7 +26,7 @@
    @Override
    public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        SensitiveService sensitiveService = SpringUtils.getBean(SensitiveService.class);
        if (sensitiveService.isSensitive()){
        if (sensitiveService.isSensitive()) {
            gen.writeString(value);
        } else {
            gen.writeString(strategy.desensitizer().apply(value));
@@ -36,7 +37,7 @@
    @Override
    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())) {
        if (Objects.nonNull(annotation) && Objects.equals(String.class, property.getType().getRawClass())) {
            this.strategy = annotation.strategy();
            return this;
        }