mirror of
https://gitee.com/BDWare/MockJava
synced 2025-01-10 09:54:05 +00:00
remove useless classes
optimize dependency
This commit is contained in:
parent
2b5b3bf001
commit
0722b05788
@ -40,7 +40,6 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
api 'com.google.code.gson:gson:2.8.8'
|
api 'com.google.code.gson:gson:2.8.8'
|
||||||
api 'log4j:log4j:1.2.17'
|
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-core:2.17.0'
|
||||||
api 'org.apache.logging.log4j:log4j-api:2.17.0'
|
api 'org.apache.logging.log4j:log4j-api:2.17.0'
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
@ -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<Object> 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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user