diff --git a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java index c8e795884a..256a1cded0 100644 --- a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java @@ -153,16 +153,27 @@ public class ReflexObjectUtil { GsonDiff diff = new GsonDiff(); Object originalValue = originalColumns.get(i).getOriginalValue(); Object newValue = newColumns.get(i).getOriginalValue(); - List originalValueArray = JSON.parseArray(originalValue.toString(), String.class); + String oldTags = null; + if (originalValue != null && !StringUtils.equals("null", originalValue.toString())) { + List originalValueArray = JSON.parseArray(originalValue.toString(), String.class); + Collections.sort(originalValueArray); + Object originalObject = JSON.toJSON(originalValueArray); + oldTags = ApiDefinitionDiffUtil.JSON_START + ((originalColumns.get(i) != null && originalObject != null) ? originalObject.toString() : "\"\"") + ApiDefinitionDiffUtil.JSON_END; + } List newValueArray = JSON.parseArray(newValue.toString(), String.class); - Collections.sort(originalValueArray); Collections.sort(newValueArray); - Object originalObject = JSON.toJSON(originalValueArray); Object newObject = JSON.toJSON(newValueArray); - String oldTags = ApiDefinitionDiffUtil.JSON_START + ((originalColumns.get(i) != null && originalObject != null) ? originalObject.toString() : "\"\"") + ApiDefinitionDiffUtil.JSON_END; String newTags = ApiDefinitionDiffUtil.JSON_START + ((newColumns.get(i) != null && newObject != null) ? newObject.toString() : "\"\"") + ApiDefinitionDiffUtil.JSON_END; - String diffStr = diff.diff(oldTags, newTags); - String diffValue = diff.apply(newTags, diffStr); + String diffValue; + if (oldTags != null) { + String diffStr = diff.diff(oldTags, newTags); + diffValue = diff.apply(newTags, diffStr); + } else { + int indexAdd = newTags.indexOf("["); + String substring = newTags.substring(0, indexAdd + 2); + String substring1 = newTags.substring(indexAdd + 2); + diffValue = substring + "++" + substring1; + } column.setDiffValue(diffValue); } // 深度对比