| | |
| | | |
| | | /** |
| | | * 数据脱敏json序列化工具 |
| | | * |
| | | * @author Yjoioooo |
| | | */ |
| | | public class SensitiveJsonSerializer extends JsonSerializer<String> implements ContextualSerializer { |
| | |
| | | @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)); |
| | |
| | | @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; |
| | | } |