ci: 请求参数统一去除前后空格

This commit is contained in:
CaptainB 2023-12-18 13:41:47 +08:00 committed by 刘瑞斌
parent 903fa6f637
commit 864f9a2d52
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package io.metersphere.system.config;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
@Configuration
public class RequestParamTrimConfig {
@Bean
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
return jacksonObjectMapperBuilder -> {
// String 类型自定义反序列化操作
jacksonObjectMapperBuilder
.deserializerByType(String.class, new StdScalarDeserializer<String>(String.class) {
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext ctx)
throws IOException {
// 去除前后空格
return StringUtils.trim(jsonParser.getValueAsString());
}
});
};
}
}