ci: 请求参数统一去除前后空格
This commit is contained in:
parent
903fa6f637
commit
864f9a2d52
|
@ -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());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue