From 998f7d49a82b0b5a9a2312fc292a310acc6fd776 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 24 Nov 2021 14:33:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(JSON-Shcema):=20=E4=BF=AE=E5=A4=8DJSON-shce?= =?UTF-8?q?ma=E5=A4=9A=E6=95=B0=E7=BB=84=E6=83=85=E5=86=B5=E4=B8=8Bjson?= =?UTF-8?q?=E8=BD=AC=E8=AF=91=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1008217 --user=宋天阳 【#7970】1.14.2版本,请求体的“JSON-SCHEMA”开关打开和关闭后,json里的信息都丢失了。json体里没有多数组的没有问题,多数组的都有问题 https://www.tapd.cn/55049933/s/1074016 --- .../commons/json/JSONSchemaGenerator.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java index 59896093b8..fd423fb09d 100644 --- a/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java +++ b/backend/src/main/java/io/metersphere/commons/json/JSONSchemaGenerator.java @@ -172,11 +172,13 @@ public class JSONSchemaGenerator { List array = new LinkedList<>(); JsonArray jsonArray = new JsonArray(); - if (object.has("items") && object.get("items").isJsonArray()) { - jsonArray = object.get("items").getAsJsonArray(); - } else { - JsonObject itemsObject = object.get("items").getAsJsonObject(); - array.add(itemsObject); + if (object.has("items")) { + if(object.get("items").isJsonArray()){ + jsonArray = object.get("items").getAsJsonArray(); + }else { + JsonObject itemsObject = object.get("items").getAsJsonObject(); + array.add(itemsObject); + } } for (int i = 0; i < jsonArray.size(); i++) {