From 26e5fb15781d02b639c8d7fb853fb4ad0ae61477 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Thu, 11 Jul 2024 13:47:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E6=A1=A3=E7=BB=93=E6=9E=84=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=EF=BC=8Cnull=E5=80=BC=E6=9C=AA=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1034687 --user=王旭 【接口测试】github#28541,接口测试-文档结构校验导入,值为null的键未导入并展示 https://www.tapd.cn/55049933/s/1546705 --- .../io/metersphere/commons/utils/JSONToDocumentUtil.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONToDocumentUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONToDocumentUtil.java index 53c8861afa..58d4f50f03 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONToDocumentUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/JSONToDocumentUtil.java @@ -12,6 +12,7 @@ import org.json.XML; import java.util.LinkedList; import java.util.List; +import java.util.Optional; public class JSONToDocumentUtil { @@ -54,6 +55,9 @@ public class JSONToDocumentUtil { jsonDataFormatting((JSONArray) value, childrenElements); } else { String type = PropertyConstant.STRING; + if (value == JSONObject.NULL || value == null) { + value = "null"; + } if (value != null) { type = DocumentUtils.getType(value); } @@ -79,7 +83,7 @@ public class JSONToDocumentUtil { } else { if (StringUtils.equals(type, "JSON")) { roots.add(new DocumentElement().newRoot(PropertyConstant.OBJECT, children)); - JSONObject object = JSONUtil.parseObject(json); + JSONObject object = new JSONObject(json); jsonDataFormatting(object, children); } else { roots.add(new DocumentElement().newRoot(PropertyConstant.OBJECT, children));