diff --git a/build.gradle b/build.gradle index bf81db1..e3752b5 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,6 @@ repositories { dependencies { api 'com.google.code.gson:gson:2.8.8' api 'log4j:log4j:1.2.17' - // api 'net.dona.doip:doip-sdk:2.1.0' api 'org.apache.logging.log4j:log4j-core:2.17.0' api 'org.apache.logging.log4j:log4j-api:2.17.0' testImplementation 'junit:junit:4.13.2' diff --git a/src/main/java/org/bdware/mockjava/JsonUtil.java b/src/main/java/org/bdware/mockjava/JsonUtil.java deleted file mode 100644 index 4f4edcb..0000000 --- a/src/main/java/org/bdware/mockjava/JsonUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.bdware.mockjava; - -import com.google.gson.*; -import jdk.nashorn.api.scripting.ScriptObjectMirror; - -import java.util.HashSet; -import java.util.Set; - -public class JsonUtil { - private static Set recorded = null; - - public static JsonElement toJson(jdk.nashorn.api.scripting.ScriptObjectMirror res) { - recorded = new HashSet<>(); - JsonElement jsonElement = copyInternal(res); - recorded.clear(); - return jsonElement; - } - - private static JsonElement copyInternal(Object obj) { - if (recorded.contains(obj)) return JsonNull.INSTANCE; - if (obj == null) return JsonNull.INSTANCE; - if (obj.getClass() == jdk.nashorn.internal.runtime.Undefined.class) - return JsonNull.INSTANCE; - if (obj.getClass() == ScriptObjectMirror.class) { - recorded.add(obj); - ScriptObjectMirror som = (ScriptObjectMirror) obj; - if (som.isFunction()) { - return JsonNull.INSTANCE; - } - if (som.isArray()) { - JsonArray jarray = new JsonArray(); - - for (String str : som.getOwnKeys(true)) { - try { - if (Integer.parseInt(str) >= 0) - jarray.add(copyInternal(som.getMember(str))); - } catch (Exception e) { - // System.out.println("[JSONTool] ignore key:"+str); - } - } - return jarray; - } else { - JsonObject jo = new JsonObject(); - for (String str : som.getOwnKeys(true)) { - jo.add(str, copyInternal(som.getMember(str))); - } - return jo; - } - } else if (obj.getClass() == jdk.internal.dynalink.beans.StaticClass.class) { - return JsonNull.INSTANCE; - } else if (obj instanceof Number) { - return new JsonPrimitive((Number) obj); - - } else if (obj instanceof String) { - return new JsonPrimitive((String) obj); - - } else if (obj instanceof Character) { - return new JsonPrimitive((Character) obj); - } - if (obj instanceof Boolean) { - return new JsonPrimitive((Boolean) obj); - } - return JsonNull.INSTANCE; - } -} \ No newline at end of file