From e30f7ef25f23b7a8f540227e51f8bd5dc3efd790 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 26 Jun 2023 10:35:58 +0800 Subject: [PATCH] =?UTF-8?q?build:=20jackson-core=20default=20maxStringLeng?= =?UTF-8?q?th=20=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fit2-zhao --- .../main/java/io/metersphere/commons/utils/JSONUtil.java | 4 ++++ .../src/main/java/io/metersphere/utils/JsonUtils.java | 6 ++++++ .../src/main/java/io/metersphere/commons/utils/JSON.java | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONUtil.java index 7fe15abfce..6c47398cb3 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONUtil.java @@ -2,6 +2,7 @@ package io.metersphere.commons.utils; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.core.StreamReadConstraints; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; @@ -45,6 +46,9 @@ public class JSONUtil { // 如果一个对象中没有任何的属性,那么在序列化的时候就会报错 objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + // 设置JSON处理字符长度限制 + objectMapper.getFactory() + .setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(JSON.DEFAULT_MAX_STRING_LEN).build()); } diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/JsonUtils.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/JsonUtils.java index 6fa51e123c..f6ccdda144 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/JsonUtils.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/JsonUtils.java @@ -2,6 +2,7 @@ package io.metersphere.utils; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.core.StreamReadConstraints; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; @@ -14,6 +15,7 @@ import java.util.List; public class JsonUtils { private static final ObjectMapper objectMapper = new ObjectMapper(); + public static final int DEFAULT_MAX_STRING_LEN = 20_000_000_0; static { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); @@ -22,6 +24,10 @@ public class JsonUtils { // 如果一个对象中没有任何的属性,那么在序列化的时候就会报错 objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + // 设置JSON处理字符长度限制 + objectMapper.getFactory() + .setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(DEFAULT_MAX_STRING_LEN).build()); + } public static String toJSONString(Object value) { diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/JSON.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/JSON.java index 567a2c362b..132a55f8cb 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/JSON.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/JSON.java @@ -3,6 +3,7 @@ package io.metersphere.commons.utils; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.StreamReadConstraints; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; @@ -19,6 +20,7 @@ import java.util.Map; public class JSON { private static final ObjectMapper objectMapper = new ObjectMapper(); private static final TypeFactory typeFactory = objectMapper.getTypeFactory(); + public static final int DEFAULT_MAX_STRING_LEN = 20_000_000_0; static { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); @@ -27,6 +29,10 @@ public class JSON { // 如果一个对象中没有任何的属性,那么在序列化的时候就会报错 objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + // 设置JSON处理字符长度限制 + objectMapper.getFactory() + .setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(DEFAULT_MAX_STRING_LEN).build()); + } public static String toJSONString(Object value) {