diff --git a/src/main/analysis/org/bdware/analysis/dynamic/ProgramPoint.java b/src/main/analysis/org/bdware/analysis/dynamic/ProgramPoint.java index 0b95ef3..e5cd34d 100644 --- a/src/main/analysis/org/bdware/analysis/dynamic/ProgramPoint.java +++ b/src/main/analysis/org/bdware/analysis/dynamic/ProgramPoint.java @@ -40,7 +40,7 @@ public class ProgramPoint { // functionMap.put(strings[1], "EXIT"); // } if (string.contains("traceMark")) { - JsonObject jo = JsonUtil.parseString(string); + JsonObject jo = JsonUtil.parseStringAsJsonObject(string); if (jo.get("traceMark") != null) { if (jo.get("lval") != null) { transaction.insert( diff --git a/src/main/analysis/org/bdware/analysis/dynamic/TracedFile.java b/src/main/analysis/org/bdware/analysis/dynamic/TracedFile.java index 40efc87..42ccccf 100644 --- a/src/main/analysis/org/bdware/analysis/dynamic/TracedFile.java +++ b/src/main/analysis/org/bdware/analysis/dynamic/TracedFile.java @@ -18,7 +18,7 @@ public class TracedFile { // TODO ignore handle contractID/method.... // TODO ignore handle transaction end while (sc.hasNextLine()) { - JsonObject jo = JsonUtil.parseString(sc.nextLine()); + JsonObject jo = JsonUtil.parseStringAsJsonObject(sc.nextLine()); if (null != jo.get("traceMark")) { if (null != jo.get("lval")) { transaction.insert(jo.get("traceMark").getAsInt(), jo.get("lval").getAsInt()); diff --git a/src/main/base/org/bdware/sc/py/PYEntry.java b/src/main/base/org/bdware/sc/py/PYEntry.java index e06f86c..8b29e57 100644 --- a/src/main/base/org/bdware/sc/py/PYEntry.java +++ b/src/main/base/org/bdware/sc/py/PYEntry.java @@ -54,7 +54,7 @@ public class PYEntry { pyYjsRequest.setYjsParams(pyYjsParams); response = HttpClient.post(ip, port, urlPath, JsonUtil.toJson(pyYjsRequest)); - JsonObject pyResponse = JsonUtil.parseString(response); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(response); return pyResponse.getAsJsonObject("yjsResult").get("objectId").getAsString(); } @@ -72,7 +72,7 @@ public class PYEntry { httpResponse = HttpClient.post(ip, port, urlPath, JsonUtil.toJson(pyYjsRequest)); - JsonObject pyResponse = JsonUtil.parseString(httpResponse); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse); return pyResponse.getAsJsonObject("yjsResult").get("objectId").getAsString(); } @@ -80,7 +80,7 @@ public class PYEntry { String urlPath = "/api/availablePackages/"; String response; response = HttpClient.get(ip, port, urlPath); - JsonObject pyResponse = JsonUtil.parseString(response); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(response); JsonObject availablePackages = pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("availablePackages"); JsonArray array = availablePackages.getAsJsonArray("packages"); @@ -98,7 +98,7 @@ public class PYEntry { String urlPath = "/api/availableModules/"; String response; response = HttpClient.get(ip, port, urlPath); - JsonObject pyResponse = JsonUtil.parseString(response); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(response); JsonObject availablePackages = pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("availableModules"); JsonArray array = availablePackages.getAsJsonArray("modules"); @@ -125,7 +125,7 @@ public class PYEntry { // "yjsResult": {"packageTotalInfo": {"package_name": "yjsexample", // "module_names": ["yjsexample.sample"]}} - JsonObject pyResponse = JsonUtil.parseString(httpResponse); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse); JsonObject packageTotalInfo = pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("packageTotalInfo"); PackageInfo packageInfo = JsonUtil.fromJson(packageTotalInfo, PackageInfo.class); @@ -161,7 +161,7 @@ public class PYEntry { // "sayHello"}, {"func_sign": "(self, name)", "func_name": "sayHello"}], // "class_name": "A"} ModuleInfo moduleInfo; - JsonObject pyResponse = JsonUtil.parseString(httpResponse); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse); JsonObject moduleInfoObj = pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("moduleInfo"); moduleInfo = JsonUtil.fromJson(moduleInfoObj, ModuleInfo.class); @@ -230,7 +230,7 @@ public class PYEntry { PYClass pyClass = new PYClass(); ClassCollection classInfo; - JsonObject pyResponse = JsonUtil.parseString(httpResponse); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse); JsonObject classInfoObj = pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("classInfo"); classInfo = JsonUtil.fromJson(classInfoObj, ClassCollection.class); @@ -289,7 +289,7 @@ public class PYEntry { pyYjsParams.setParams(PYMethodParams); pyYjsRequest.setYjsParams(pyYjsParams); httpResponse = HttpClient.post(ip, port, urlPath, JsonUtil.toJson(pyYjsRequest)); - JsonObject pyResponse = JsonUtil.parseString(httpResponse); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse); JsonObject ysjResult = pyResponse.getAsJsonObject("yjsResult"); return ysjResult.toString(); } @@ -308,7 +308,7 @@ public class PYEntry { pyYjsParams.setParams(PYMethodParams); pyYjsRequest.setYjsParams(pyYjsParams); httpResponse = HttpClient.post(ip, port, urlPath, JsonUtil.toJson(pyYjsRequest)); - JsonObject pyResponse = JsonUtil.parseString(httpResponse); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse); JsonObject ysjResult = pyResponse.getAsJsonObject("yjsResult"); return ysjResult.toString(); } @@ -329,7 +329,7 @@ public class PYEntry { pyYjsParams.setParams(PYMethodParams); pyYjsRequest.setYjsParams(pyYjsParams); httpResponse = HttpClient.post(ip, port, urlPath, JsonUtil.toJson(pyYjsRequest)); - JsonObject pyResponse = JsonUtil.parseString(httpResponse); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse); JsonObject ysjResult = pyResponse.getAsJsonObject("yjsResult"); return ysjResult.toString(); } @@ -352,7 +352,7 @@ public class PYEntry { pyYjsRequest.setYjsParams(pyYjsParams); System.out.println(JsonUtil.toJson(pyYjsRequest)); httpResponse = HttpClient.post(ip, port, urlPath, JsonUtil.toJson(pyYjsRequest)); - JsonObject pyResponse = JsonUtil.parseString(httpResponse); + JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse); JsonObject ysjResult = pyResponse.getAsJsonObject("yjsResult"); return ysjResult.toString(); } diff --git a/src/main/base/org/bdware/sc/util/JsonUtil.java b/src/main/base/org/bdware/sc/util/JsonUtil.java index f02dd62..de88174 100644 --- a/src/main/base/org/bdware/sc/util/JsonUtil.java +++ b/src/main/base/org/bdware/sc/util/JsonUtil.java @@ -37,11 +37,15 @@ public class JsonUtil { return PRETTY_GSON.toJson(o); } - public static JsonObject parseString(String json) { + public static JsonObject parseStringAsJsonObject(String json) { return JsonParser.parseString(json).getAsJsonObject(); } - public static JsonObject parseObject(Object obj) { + public static JsonObject parseReaderAsJsonObject(Reader reader) { + return JsonParser.parseReader(reader).getAsJsonObject(); + } + + public static JsonObject parseObjectAsJsonObject(Object obj) { return GSON.toJsonTree(obj).getAsJsonObject(); } } diff --git a/src/main/entry/org/bdware/sc/db/MultiIndexTimeDBUtil.java b/src/main/entry/org/bdware/sc/db/MultiIndexTimeDBUtil.java index 5518b8f..3ea35d1 100644 --- a/src/main/entry/org/bdware/sc/db/MultiIndexTimeDBUtil.java +++ b/src/main/entry/org/bdware/sc/db/MultiIndexTimeDBUtil.java @@ -96,7 +96,7 @@ public class MultiIndexTimeDBUtil implements MultiIndexTimeDBUtilIntf { try { t = db.readFromDatabase(l.toString()); if (t != null && !t.isEmpty()) { - JsonObject jo = JsonUtil.parseString(t); + JsonObject jo = JsonUtil.parseStringAsJsonObject(t); jo.addProperty("key", l.toString()); ret.add(jo); } @@ -130,7 +130,7 @@ public class MultiIndexTimeDBUtil implements MultiIndexTimeDBUtilIntf { String t = db.readFromDatabase(l.toString()); JsonObject jo; if (t != null && !t.isEmpty()) { - jo = JsonUtil.parseString(t); + jo = JsonUtil.parseStringAsJsonObject(t); } else { jo = new JsonObject(); } diff --git a/src/main/entry/org/bdware/sc/db/MultiIndexTimeRocksDBUtil.java b/src/main/entry/org/bdware/sc/db/MultiIndexTimeRocksDBUtil.java index 52f618f..0f9f50b 100644 --- a/src/main/entry/org/bdware/sc/db/MultiIndexTimeRocksDBUtil.java +++ b/src/main/entry/org/bdware/sc/db/MultiIndexTimeRocksDBUtil.java @@ -124,7 +124,7 @@ public class MultiIndexTimeRocksDBUtil implements MultiIndexTimeDBUtilIntf { try { t = new String(db.get(longToByte(l))); if (!t.isEmpty()) { - JsonObject jo = JsonUtil.parseString(t); + JsonObject jo = JsonUtil.parseStringAsJsonObject(t); jo.addProperty("key", l.toString()); ret.add(jo); } @@ -158,7 +158,7 @@ public class MultiIndexTimeRocksDBUtil implements MultiIndexTimeDBUtilIntf { String t = new String(db.get(longToByte(l))); JsonObject jo; if (!t.isEmpty()) { - jo = JsonUtil.parseString(t); + jo = JsonUtil.parseStringAsJsonObject(t); } else { jo = new JsonObject(); } @@ -246,7 +246,7 @@ public class MultiIndexTimeRocksDBUtil implements MultiIndexTimeDBUtilIntf { RocksIterator iter = db.newIterator(); iter.seekToFirst(); for (; iter.isValid(); iter.next()) { - JsonObject jo = JsonUtil.parseString(new String(iter.value())); + JsonObject jo = JsonUtil.parseStringAsJsonObject(new String(iter.value())); Long time = jo.get("date").getAsLong(); if (time < 0) { continue; diff --git a/src/main/entry/org/bdware/sc/db/TimeDBUtil.java b/src/main/entry/org/bdware/sc/db/TimeDBUtil.java index 27924e1..abe4246 100644 --- a/src/main/entry/org/bdware/sc/db/TimeDBUtil.java +++ b/src/main/entry/org/bdware/sc/db/TimeDBUtil.java @@ -134,7 +134,7 @@ public class TimeDBUtil { try { String t = db.readFromDatabase(l.toString()); if (null != t && !t.isEmpty()) { - JsonObject jo = JsonUtil.parseString(t); + JsonObject jo = JsonUtil.parseStringAsJsonObject(t); jo.addProperty("key", l.toString()); if (jo.has("contractName") && jo.get("contractName").getAsString().equals(contractName)) { @@ -293,7 +293,7 @@ public class TimeDBUtil { for (Long l : data) { try { String t = db.readFromDatabase(l.toString()); - data2 = JsonUtil.parseString(t); + data2 = JsonUtil.parseStringAsJsonObject(t); ret.add(data2); } catch (Exception e) { e.printStackTrace(); @@ -323,7 +323,7 @@ public class TimeDBUtil { try { t = db.readFromDatabase(l.toString()); - data2 = JsonUtil.parseString(t); + data2 = JsonUtil.parseStringAsJsonObject(t); ret.add(data2); } catch (Exception e) { LOGGER.error("parse json error:" + t); diff --git a/src/main/entry/org/bdware/sc/db/TimeRocksDBUtil.java b/src/main/entry/org/bdware/sc/db/TimeRocksDBUtil.java index 263e8e7..db8ae05 100644 --- a/src/main/entry/org/bdware/sc/db/TimeRocksDBUtil.java +++ b/src/main/entry/org/bdware/sc/db/TimeRocksDBUtil.java @@ -145,7 +145,7 @@ public class TimeRocksDBUtil { try { String t = new String(db.get(l.toString().getBytes(StandardCharsets.UTF_8))); if (null != t && !t.isEmpty()) { - JsonObject jo = JsonUtil.parseString(t); + JsonObject jo = JsonUtil.parseStringAsJsonObject(t); jo.addProperty("key", l.toString()); if (jo.has("contractName") && jo.get("contractName").getAsString().equals(contractName)) {