diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/config/RequestParamTrimConfig.java b/backend/services/system-setting/src/main/java/io/metersphere/system/config/RequestParamTrimConfig.java new file mode 100644 index 0000000000..c2aa6db8af --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/config/RequestParamTrimConfig.java @@ -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.class) { + @Override + public String deserialize(JsonParser jsonParser, DeserializationContext ctx) + throws IOException { + // 去除前后空格 + return StringUtils.trim(jsonParser.getValueAsString()); + } + }); + }; + } +} \ No newline at end of file