diff --git a/backend/src/main/java/io/metersphere/log/utils/dff/ApiDefinitionDiffUtil.java b/backend/src/main/java/io/metersphere/log/utils/ApiDefinitionDiffUtil.java similarity index 98% rename from backend/src/main/java/io/metersphere/log/utils/dff/ApiDefinitionDiffUtil.java rename to backend/src/main/java/io/metersphere/log/utils/ApiDefinitionDiffUtil.java index 942228419b..feb479c430 100644 --- a/backend/src/main/java/io/metersphere/log/utils/dff/ApiDefinitionDiffUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ApiDefinitionDiffUtil.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.dff; +package io.metersphere.log.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -7,9 +7,8 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler; import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler; import io.metersphere.api.dto.scenario.Body; -import io.metersphere.log.utils.ReflexObjectUtil; -import io.metersphere.log.utils.json.diff.JacksonDiff; -import io.metersphere.log.utils.json.diff.JsonDiff; +import io.metersphere.log.utils.diff.json.JacksonDiff; +import io.metersphere.log.utils.diff.json.JsonDiff; import io.metersphere.log.vo.DetailColumn; import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.api.DefinitionReference; @@ -21,8 +20,8 @@ import java.util.List; import java.util.Map; public class ApiDefinitionDiffUtil { - static final String JSON_START = "{\"root\":"; - static final String JSON_END = "}"; + public static final String JSON_START = "{\"root\":"; + public static final String JSON_END = "}"; public static String diffResponse(String newValue, String oldValue) { Map diffMap = new LinkedHashMap<>(); 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 336676b1ef..dafa9cdbf0 100644 --- a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java @@ -7,8 +7,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.LogUtil; -import io.metersphere.log.utils.dff.ApiDefinitionDiffUtil; -import io.metersphere.log.utils.json.diff.GsonDiff; +import io.metersphere.log.utils.diff.json.GsonDiff; import io.metersphere.log.vo.DetailColumn; import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.StatusReference; @@ -19,6 +18,7 @@ import java.util.*; import java.util.stream.Collectors; public class ReflexObjectUtil { + static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); public static List getColumns(Object obj, Map columns) { List columnList = new LinkedList<>(); @@ -30,7 +30,45 @@ public class ReflexObjectUtil { if (StringUtils.isNotEmpty(dffValue)) { dffColumns = Arrays.asList(dffValue.split(",")); } - // 得到类对象 + // 得到类中的所有属性集合 + List fields = getFields(obj); + try { + for (Field[] fs : fields) { + for (int i = 0; i < fs.length; i++) { + Field f = fs[i]; + f.setAccessible(true); + if (columns.containsKey(f.getName())) { + Object val = f.get(obj); + if (StatusReference.statusMap.containsKey(String.valueOf(val))) { + val = StatusReference.statusMap.get(String.valueOf(val)); + } + DetailColumn column = new DetailColumn(columns.get(f.getName()), f.getName(), val, ""); + if (dffColumns.contains(f.getName())) { + column.setDepthDff(true); + column.setOriginalValue(formatJson(val)); + } + columnList.add(column); + } + } + } + } catch (Exception e) { + LogUtil.error(e); + } + List keys = columns.keySet().stream().collect(Collectors.toList()); + ReflexObjectUtil.order(keys, columnList); + return columnList; + } + + static Object formatJson(Object val) { + try { + JsonObject jsonObject = gson.fromJson(String.valueOf(val), JsonObject.class); + return gson.toJson(jsonObject); + } catch (Exception e) { + return val; + } + } + + static List getFields(Object obj) { Class clazz = obj.getClass(); // 得到类中的所有属性集合 List fields = new LinkedList<>(); @@ -42,40 +80,7 @@ public class ReflexObjectUtil { // 获得父类的字节码对象 clazz = clazz.getSuperclass(); } - for (Field[] fs : fields) { - for (int i = 0; i < fs.length; i++) { - Field f = fs[i]; - f.setAccessible(true); - try { - if (columns.containsKey(f.getName())) { - Object val = f.get(obj); - if (val != null && StatusReference.statusMap.containsKey(val.toString())) { - val = StatusReference.statusMap.get(val.toString()); - } - DetailColumn column = new DetailColumn(columns.get(f.getName()), f.getName(), val, ""); - if (dffColumns.contains(f.getName())) { - column.setDepthDff(true); - if (val != null) { - try { - // 格式化 - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - JsonObject jsonObject = gson.fromJson(val.toString(), JsonObject.class); - column.setOriginalValue(gson.toJson(jsonObject)); - } catch (Exception e) { - - } - } - } - columnList.add(column); - } - } catch (Exception e) { - LogUtil.error(e); - } - } - } - List keys = columns.keySet().stream().collect(Collectors.toList()); - ReflexObjectUtil.order(keys, columnList); - return columnList; + return fields; } public static List getColumns(Object obj) { @@ -83,18 +88,8 @@ public class ReflexObjectUtil { if (obj == null) { return columnList; } - // 得到类对象 - Class clazz = obj.getClass(); // 得到类中的所有属性集合 - List fields = new LinkedList<>(); - // 遍历所有父类字节码对象 - while (clazz != null) { - // 获取字节码对象的属性对象数组 - Field[] declaredFields = clazz.getDeclaredFields(); - fields.add(declaredFields); - // 获得父类的字节码对象 - clazz = clazz.getSuperclass(); - } + List fields = getFields(obj); for (Field[] fs : fields) { for (int i = 0; i < fs.length; i++) { Field f = fs[i]; @@ -156,8 +151,8 @@ public class ReflexObjectUtil { column.setNewValue(newColumns.get(i).getOriginalValue()); if (StringUtils.isNotEmpty(originalColumns.get(i).getColumnName()) && originalColumns.get(i).getColumnName().equals("tags")) { GsonDiff diff = new GsonDiff(); - String oldTags = "{\"root\":" + ((originalColumns.get(i) != null && originalColumns.get(i).getOriginalValue() != null) ? originalColumns.get(i).getOriginalValue().toString() : "\"\"") + "}"; - String newTags = "{\"root\":" + ((newColumns.get(i) != null && newColumns.get(i).getOriginalValue() != null) ? newColumns.get(i).getOriginalValue().toString() : "\"\"") + "}"; + String oldTags = ApiDefinitionDiffUtil.JSON_START + ((originalColumns.get(i) != null && originalColumns.get(i).getOriginalValue() != null) ? originalColumns.get(i).getOriginalValue().toString() : "\"\"") + ApiDefinitionDiffUtil.JSON_END; + String newTags = ApiDefinitionDiffUtil.JSON_START + ((newColumns.get(i) != null && newColumns.get(i).getOriginalValue() != null) ? newColumns.get(i).getOriginalValue().toString() : "\"\"") + ApiDefinitionDiffUtil.JSON_END; String diffStr = diff.diff(oldTags, newTags); String diffValue = diff.apply(newTags, diffStr); column.setDiffValue(diffValue); @@ -174,17 +169,13 @@ public class ReflexObjectUtil { column.setDiffValue(ApiDefinitionDiffUtil.diffResponse(newValue, oldValue)); } } else { - try { - String newValue = column.getNewValue().toString(); - if (StringUtils.isNotEmpty(newValue)) { - column.setNewValue(newValue.replaceAll("\\n", " ")); - } - String oldValue = column.getOriginalValue().toString(); - if (StringUtils.isNotEmpty(oldValue)) { - column.setOriginalValue(oldValue.replaceAll("\\n", " ")); - } - } catch (Exception e) { - + String newValue = column.getNewValue().toString(); + if (StringUtils.isNotEmpty(newValue)) { + column.setNewValue(newValue.replaceAll("\\n", " ")); + } + String oldValue = column.getOriginalValue().toString(); + if (StringUtils.isNotEmpty(oldValue)) { + column.setOriginalValue(oldValue.replaceAll("\\n", " ")); } } comparedColumns.add(column); diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/ArrNode.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/ArrNode.java similarity index 94% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/ArrNode.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/ArrNode.java index a60676c37f..c59510aa43 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/ArrNode.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/ArrNode.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; class ArrNode extends Node { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/GsonDiff.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/GsonDiff.java similarity index 74% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/GsonDiff.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/GsonDiff.java index 581174105f..194ca7d374 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/GsonDiff.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/GsonDiff.java @@ -1,9 +1,9 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import io.metersphere.log.utils.json.diff.jsonwrap.gson.GsonWrapper; +import io.metersphere.log.utils.diff.json.jsonwrap.gson.GsonWrapper; public class GsonDiff extends JsonDiff { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/IncavaDiff.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/IncavaDiff.java similarity index 99% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/IncavaDiff.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/IncavaDiff.java index 27c27ff076..badf846168 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/IncavaDiff.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/IncavaDiff.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; import java.util.*; diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/IncavaEntry.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/IncavaEntry.java similarity index 99% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/IncavaEntry.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/IncavaEntry.java index e601774a56..12c030db16 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/IncavaEntry.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/IncavaEntry.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; /* Copyright (c) 2009, incava.org diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/JacksonDiff.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/JacksonDiff.java similarity index 52% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/JacksonDiff.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/JacksonDiff.java index 88b3ca8db2..4a2ed7e477 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/JacksonDiff.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/JacksonDiff.java @@ -1,6 +1,6 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; -import io.metersphere.log.utils.json.diff.jsonwrap.jackson.JacksonWrapper; +import io.metersphere.log.utils.diff.json.jsonwrap.jackson.JacksonWrapper; public class JacksonDiff extends JsonDiff { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/JsonDiff.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/JsonDiff.java similarity index 98% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/JsonDiff.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/JsonDiff.java index 15661f741d..09ef609fc2 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/JsonDiff.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/JsonDiff.java @@ -1,12 +1,12 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; import com.google.gson.JsonPrimitive; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonArray; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonObject; -import io.metersphere.log.utils.json.diff.jsonwrap.Wrapper; -import io.metersphere.log.utils.json.diff.jsonwrap.gson.GsonJsonPrimitive; -import io.metersphere.log.utils.json.diff.jsonwrap.jackson.JacksonJsonObject; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonArray; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonObject; +import io.metersphere.log.utils.diff.json.jsonwrap.Wrapper; +import io.metersphere.log.utils.diff.json.jsonwrap.gson.GsonJsonPrimitive; +import io.metersphere.log.utils.diff.json.jsonwrap.jackson.JacksonJsonObject; import org.apache.commons.lang3.StringUtils; import java.util.*; diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/Leaf.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/Leaf.java similarity index 97% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/Leaf.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/Leaf.java index f871664795..c965ec7ecf 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/Leaf.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/Leaf.java @@ -1,9 +1,9 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonArray; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonObject; -import io.metersphere.log.utils.json.diff.jsonwrap.Wrapper; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonArray; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonObject; +import io.metersphere.log.utils.diff.json.jsonwrap.Wrapper; import java.util.*; import java.util.logging.Level; diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/Node.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/Node.java similarity index 94% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/Node.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/Node.java index 14355ec181..72d80f9e7c 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/Node.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/Node.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; abstract class Node implements Cloneable { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/ObjNode.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/ObjNode.java similarity index 93% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/ObjNode.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/ObjNode.java index 6049e9813e..e3f041f247 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/ObjNode.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/ObjNode.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; class ObjNode extends Node { diff --git a/backend/src/main/java/io/metersphere/log/utils/diff/json/Oper.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/Oper.java new file mode 100644 index 0000000000..4a45fa0090 --- /dev/null +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/Oper.java @@ -0,0 +1,5 @@ +package io.metersphere.log.utils.diff.json; + +enum Oper { + INSERT, DELETE, SET +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/Root.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/Root.java similarity index 87% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/Root.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/Root.java index 065c7bd065..fac049044c 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/Root.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/Root.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; class Root extends Node { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/Visitor.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/Visitor.java similarity index 90% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/Visitor.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/Visitor.java index c759da6b1f..7b4882b3d4 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/Visitor.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/Visitor.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff; +package io.metersphere.log.utils.diff.json; /** diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonArray.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonArray.java similarity index 94% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonArray.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonArray.java index 426c94a8e9..e555db2a7b 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonArray.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonArray.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap; +package io.metersphere.log.utils.diff.json.jsonwrap; /** * Common abstaraction for a json array. diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonElement.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonElement.java similarity index 90% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonElement.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonElement.java index cb66cc817b..c0ece69781 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonElement.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonElement.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap; +package io.metersphere.log.utils.diff.json.jsonwrap; /** * Common abstraction for json elements. diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonNull.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonNull.java similarity index 68% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonNull.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonNull.java index 5c5fed74ef..0aad75a7c1 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonNull.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonNull.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap; +package io.metersphere.log.utils.diff.json.jsonwrap; /** * Common abstraction for json null. diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonObject.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonObject.java similarity index 95% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonObject.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonObject.java index 50f9e0820a..d71e881712 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonObject.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonObject.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap; +package io.metersphere.log.utils.diff.json.jsonwrap; import java.util.Collection; import java.util.Map.Entry; diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonPrimitive.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonPrimitive.java similarity index 71% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonPrimitive.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonPrimitive.java index 96dc1e92fc..3f6f3a3596 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/JzonPrimitive.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/JzonPrimitive.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap; +package io.metersphere.log.utils.diff.json.jsonwrap; /** * Common abstraction for json primitive values. diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/Wrapper.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/Wrapper.java similarity index 92% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/Wrapper.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/Wrapper.java index 511692d8c3..5c97e9c3ca 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/Wrapper.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/Wrapper.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap; +package io.metersphere.log.utils.diff.json.jsonwrap; /** * Factory wrapper interface for multiple json implementations. diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonArray.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonArray.java similarity index 88% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonArray.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonArray.java index c63b000a2b..d2f8c046b1 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonArray.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonArray.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.gson; +package io.metersphere.log.utils.diff.json.jsonwrap.gson; import java.lang.reflect.Field; import java.util.ArrayList; @@ -6,8 +6,8 @@ import java.util.ArrayList; import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonArray; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonArray; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; public class GsonJsonArray extends GsonJsonElement implements JzonArray { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonElement.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonElement.java similarity index 88% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonElement.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonElement.java index 37e964ef33..43fb025c8c 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonElement.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonElement.java @@ -1,8 +1,8 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.gson; +package io.metersphere.log.utils.diff.json.jsonwrap.gson; import com.google.gson.JsonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; public class GsonJsonElement implements JzonElement { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonNull.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonNull.java similarity index 70% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonNull.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonNull.java index 7b46c65c4c..3da2ca5616 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonNull.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonNull.java @@ -1,8 +1,8 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.gson; +package io.metersphere.log.utils.diff.json.jsonwrap.gson; import com.google.gson.JsonNull; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonNull; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonNull; public class GsonJsonNull extends GsonJsonElement implements JzonNull { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonObject.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonObject.java similarity index 91% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonObject.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonObject.java index f07c8b0cf3..e3b910fc0c 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonObject.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonObject.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.gson; +package io.metersphere.log.utils.diff.json.jsonwrap.gson; import java.util.Collection; import java.util.HashSet; @@ -8,8 +8,8 @@ import java.util.Set; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonObject; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonObject; public class GsonJsonObject extends GsonJsonElement implements JzonObject { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonPrimitive.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonPrimitive.java similarity index 63% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonPrimitive.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonPrimitive.java index 5a3dc5c981..4b6137af89 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonJsonPrimitive.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonJsonPrimitive.java @@ -1,8 +1,8 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.gson; +package io.metersphere.log.utils.diff.json.jsonwrap.gson; import com.google.gson.JsonPrimitive; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonPrimitive; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonPrimitive; public class GsonJsonPrimitive extends GsonJsonElement implements JzonPrimitive { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonWrapper.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonWrapper.java similarity index 77% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonWrapper.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonWrapper.java index 641208005d..538cd215d1 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/gson/GsonWrapper.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/gson/GsonWrapper.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.gson; +package io.metersphere.log.utils.diff.json.jsonwrap.gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -6,10 +6,10 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonArray; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonObject; -import io.metersphere.log.utils.json.diff.jsonwrap.Wrapper; +import io.metersphere.log.utils.diff.json.jsonwrap.Wrapper; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonArray; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonObject; public class GsonWrapper implements Wrapper { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonArray.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonArray.java similarity index 81% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonArray.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonArray.java index 50cc6d3583..53308ebd28 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonArray.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonArray.java @@ -1,10 +1,10 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson; +package io.metersphere.log.utils.diff.json.jsonwrap.jackson; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.node.ArrayNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonArray; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonArray; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; public class JacksonJsonArray extends JacksonJsonElement implements JzonArray { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonElement.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonElement.java similarity index 88% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonElement.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonElement.java index 4eda8187ec..6b20d6f11c 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonElement.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonElement.java @@ -1,8 +1,8 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson; +package io.metersphere.log.utils.diff.json.jsonwrap.jackson; import org.codehaus.jackson.JsonNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; public class JacksonJsonElement implements JzonElement { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonNull.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonNull.java similarity index 72% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonNull.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonNull.java index 0a29f1d4af..d4e99508ca 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonNull.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonNull.java @@ -1,8 +1,8 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson; +package io.metersphere.log.utils.diff.json.jsonwrap.jackson; import org.codehaus.jackson.node.NullNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonNull; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonNull; public class JacksonJsonNull extends JacksonJsonElement implements JzonNull { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonObject.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonObject.java similarity index 91% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonObject.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonObject.java index 1931cf836d..92bcc278f6 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonObject.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonObject.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson; +package io.metersphere.log.utils.diff.json.jsonwrap.jackson; import java.util.Collection; import java.util.HashSet; @@ -8,8 +8,8 @@ import java.util.Map.Entry; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.node.ObjectNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonObject; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonObject; public class JacksonJsonObject extends JacksonJsonElement implements JzonObject { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonPrimitive.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonPrimitive.java similarity index 64% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonPrimitive.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonPrimitive.java index d061c2c818..70e15a1ed6 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonJsonPrimitive.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonJsonPrimitive.java @@ -1,8 +1,8 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson; +package io.metersphere.log.utils.diff.json.jsonwrap.jackson; import org.codehaus.jackson.node.ValueNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonPrimitive; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonPrimitive; public class JacksonJsonPrimitive extends JacksonJsonElement implements JzonPrimitive { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonWrapper.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonWrapper.java similarity index 84% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonWrapper.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonWrapper.java index cbd2789d8a..8e46cbdedf 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonWrapper.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonWrapper.java @@ -1,7 +1,8 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson; +package io.metersphere.log.utils.diff.json.jsonwrap.jackson; import java.io.IOException; +import io.metersphere.log.utils.diff.json.jsonwrap.Wrapper; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonProcessingException; @@ -10,10 +11,9 @@ import org.codehaus.jackson.node.ArrayNode; import org.codehaus.jackson.node.ObjectNode; import org.codehaus.jackson.node.ValueNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonArray; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonObject; -import io.metersphere.log.utils.json.diff.jsonwrap.Wrapper; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonArray; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; +import io.metersphere.log.utils.diff.json.jsonwrap.JzonObject; public class JacksonWrapper implements Wrapper { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonWrapperException.java b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonWrapperException.java similarity index 86% rename from backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonWrapperException.java rename to backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonWrapperException.java index c8a730fb89..dc98e4bcd3 100644 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson/JacksonWrapperException.java +++ b/backend/src/main/java/io/metersphere/log/utils/diff/json/jsonwrap/jackson/JacksonWrapperException.java @@ -1,4 +1,4 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson; +package io.metersphere.log.utils.diff.json.jsonwrap.jackson; @SuppressWarnings("serial") public class JacksonWrapperException extends RuntimeException { diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/DiffTest.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/DiffTest.java deleted file mode 100644 index e375a136f7..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/DiffTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.metersphere.log.utils.json.diff; - -public class DiffTest { - public static void main(String[] args) { - GsonDiff diff = new GsonDiff(); - - String newValue= "{\n" + - " \"username\": \"zyy\",\n" + - " \"username2\": \"zyy\",\n" + - " \"password\": \"Calong@2015\"\n" + - "}"; - String oldValue = "{\n" + - " \"username\": \"zyy\",\n" + - " \"username1\": \"zyy\",\n" + - " \"password\": \"Calong@201512\"\n" + - "}"; - String d = diff.diff(oldValue,newValue); - - System.out.println(d); - - System.out.println(diff.apply(newValue,d)); - } -} diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/Jackson2Diff.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/Jackson2Diff.java deleted file mode 100644 index 2812916257..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/Jackson2Diff.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.metersphere.log.utils.json.diff; - -import io.metersphere.log.utils.json.diff.jsonwrap.jackson2.Jackson2Wrapper; - -public class Jackson2Diff extends JsonDiff { - - public Jackson2Diff() { - super(new Jackson2Wrapper()); - } - -} diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/Oper.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/Oper.java deleted file mode 100644 index 9e8d2328ec..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/Oper.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.metersphere.log.utils.json.diff; - -enum Oper { - INSERT, DELETE, SET -} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonArray.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonArray.java deleted file mode 100644 index 3fc1c29b18..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonArray.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson2; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonArray; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; - -public class Jackson2JsonArray extends Jackson2JsonElement implements JzonArray { - - private final ArrayNode wrapped; - - public Jackson2JsonArray(ArrayNode wrapped) { - super(wrapped); - this.wrapped = wrapped; - } - - @Override - public int size() { - return wrapped.size(); - } - - @Override - public JzonElement get(int index) { - return Jackson2Wrapper.wrap(wrapped.get(index)); - } - - @Override - public void insert(int index, JzonElement el) { - wrapped.insert(index, (JsonNode) el.unwrap()); - } - - @Override - public void set(int index, JzonElement el) { - wrapped.set(index, (JsonNode) el.unwrap()); - } - - @Override - public void remove(int index) { - wrapped.remove(index); - } - - @Override - public String toString() { - return wrapped.toString(); - } - -} diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonElement.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonElement.java deleted file mode 100644 index cacb8a240c..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonElement.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson2; - - -import com.fasterxml.jackson.databind.JsonNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; - - -public class Jackson2JsonElement implements JzonElement { - - final JsonNode wrapped; - - - protected Jackson2JsonElement(JsonNode wrapped) { - this.wrapped = wrapped; - } - - - @Override - public boolean isJsonObject() { - return wrapped.isObject(); - } - - - @Override - public boolean isJsonArray() { - return wrapped.isArray(); - } - - - @Override - public boolean isJsonPrimitive() { - return wrapped.isValueNode(); - } - - - @Override - public boolean isJsonNull() { - return wrapped.isNull(); - } - - - @Override - public Object unwrap() { - return wrapped; - } - - - @Override - public String toString() { - return wrapped.toString(); - } - - - @Override - public boolean equals(Object obj) { - return wrapped.equals(obj); - } - - - @Override - public int hashCode() { - return wrapped.hashCode(); - } - -} diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonNull.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonNull.java deleted file mode 100644 index 66993d5316..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonNull.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson2; - - -import com.fasterxml.jackson.databind.node.NullNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonNull; - - -public class Jackson2JsonNull extends Jackson2JsonElement implements JzonNull { - - static final NullNode JNULL = NullNode.getInstance(); - - - public final static Jackson2JsonNull INSTANCE = new Jackson2JsonNull(); - - - public Jackson2JsonNull() { - super(JNULL); - } - -} diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonObject.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonObject.java deleted file mode 100644 index 64c9db5a1e..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonObject.java +++ /dev/null @@ -1,98 +0,0 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson2; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonObject; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map.Entry; - - -public class Jackson2JsonObject extends Jackson2JsonElement implements JzonObject { - - private final ObjectNode wrapped; - - - public Jackson2JsonObject(ObjectNode wrapped) { - super(wrapped); - this.wrapped = wrapped; - } - - - @Override - public boolean has(String key) { - return wrapped.has(key); - } - - - @Override - public void add(String key, JzonElement prop) { - wrapped.put(key, (JsonNode) prop.unwrap()); - } - - - @Override - public void addProperty(String key, int prop) { - wrapped.put(key, prop); - } - - - @Override - public Collection> entrySet() { - - HashSet> jset = new HashSet>(); - - for (Iterator> i = wrapped.fields() ; i.hasNext();) { - - final Entry e = i.next(); - - final JzonElement el = Jackson2Wrapper.wrap(e.getValue()); - - jset.add(new Entry() { - - @Override - public String getKey() { - return e.getKey(); - } - - - @Override - public JzonElement getValue() { - return el; - } - - - @Override - public JzonElement setValue(JzonElement value) { - throw new UnsupportedOperationException(); - } - }); - } - - return jset; - - } - - - @Override - public JzonElement get(String key) { - return Jackson2Wrapper.wrap(wrapped.get(key)); - } - - - @Override - public void remove(String key) { - wrapped.remove(key); - } - - - @Override - public String toString() { - return wrapped.toString(); - } - - -} diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonPrimitive.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonPrimitive.java deleted file mode 100644 index d347491be8..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2JsonPrimitive.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson2; - -import com.fasterxml.jackson.databind.node.ValueNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonPrimitive; - - -public class Jackson2JsonPrimitive extends Jackson2JsonElement implements JzonPrimitive { - - public Jackson2JsonPrimitive(ValueNode wrapped) { - super(wrapped); - } - -} diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2Wrapper.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2Wrapper.java deleted file mode 100644 index 242e316d56..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2Wrapper.java +++ /dev/null @@ -1,64 +0,0 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson2; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.node.ValueNode; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonArray; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonElement; -import io.metersphere.log.utils.json.diff.jsonwrap.JzonObject; -import io.metersphere.log.utils.json.diff.jsonwrap.Wrapper; - -import java.io.IOException; - -public class Jackson2Wrapper implements Wrapper { - - private final static ObjectMapper JSON = new ObjectMapper(); - - public static JzonElement wrap(JsonNode el) { - if (el == null || el.isNull()) { - return Jackson2JsonNull.INSTANCE; - } else if (el.isArray()) { - return new Jackson2JsonArray((ArrayNode) el); - } else if (el.isObject()) { - return new Jackson2JsonObject((ObjectNode) el); - } else if (el.isValueNode()) { - return new Jackson2JsonPrimitive((ValueNode) el); - } else { - throw new IllegalStateException(); - } - } - - @Override - public JzonElement parse(String json) { - try { - JsonParser parser = JSON.getJsonFactory().createJsonParser(json); - parser.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); - parser.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - return wrap(parser.readValueAsTree()); - } catch (JsonProcessingException e) { - throw new Jackson2WrapperException("Failed to parse JSON", e); - } catch (IOException e) { - throw new Jackson2WrapperException("IOException parsing a String?", e); - } - } - - @Override - public JzonElement wrap(Object o) { - return wrap((JsonNode) o); - } - - @Override - public JzonObject createJsonObject() { - return (JzonObject) wrap(JSON.createObjectNode()); - } - - @Override - public JzonArray createJsonArray() { - return (JzonArray) wrap(JSON.createArrayNode()); - } - -} diff --git a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2WrapperException.java b/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2WrapperException.java deleted file mode 100644 index 3a60baf323..0000000000 --- a/backend/src/main/java/io/metersphere/log/utils/json/diff/jsonwrap/jackson2/Jackson2WrapperException.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.metersphere.log.utils.json.diff.jsonwrap.jackson2; - -@SuppressWarnings("serial") -public class Jackson2WrapperException extends RuntimeException { - - public Jackson2WrapperException() { - super(); - } - - public Jackson2WrapperException(String message, Throwable cause) { - super(message, cause); - } - - public Jackson2WrapperException(String message) { - super(message); - } - - public Jackson2WrapperException(Throwable cause) { - super(cause); - } - -}