mirror of
https://gitee.com/BDWare/common
synced 2025-01-26 09:44:12 +00:00
feat: udpate JsonUtil
rename JsonUtil.parseString to JsonUtil.parseStringAsJsonObject, rename JsonUtil.parseObject to JsonUtil.parseObjectAsJsonObject; add JsonUtil.parseReaderAsJsonObject
This commit is contained in:
parent
2cfd82bb4b
commit
c1654034ac
@ -40,7 +40,7 @@ public class ProgramPoint {
|
|||||||
// functionMap.put(strings[1], "EXIT");
|
// functionMap.put(strings[1], "EXIT");
|
||||||
// }
|
// }
|
||||||
if (string.contains("traceMark")) {
|
if (string.contains("traceMark")) {
|
||||||
JsonObject jo = JsonUtil.parseString(string);
|
JsonObject jo = JsonUtil.parseStringAsJsonObject(string);
|
||||||
if (jo.get("traceMark") != null) {
|
if (jo.get("traceMark") != null) {
|
||||||
if (jo.get("lval") != null) {
|
if (jo.get("lval") != null) {
|
||||||
transaction.insert(
|
transaction.insert(
|
||||||
|
@ -18,7 +18,7 @@ public class TracedFile {
|
|||||||
// TODO ignore handle contractID/method....
|
// TODO ignore handle contractID/method....
|
||||||
// TODO ignore handle transaction end
|
// TODO ignore handle transaction end
|
||||||
while (sc.hasNextLine()) {
|
while (sc.hasNextLine()) {
|
||||||
JsonObject jo = JsonUtil.parseString(sc.nextLine());
|
JsonObject jo = JsonUtil.parseStringAsJsonObject(sc.nextLine());
|
||||||
if (null != jo.get("traceMark")) {
|
if (null != jo.get("traceMark")) {
|
||||||
if (null != jo.get("lval")) {
|
if (null != jo.get("lval")) {
|
||||||
transaction.insert(jo.get("traceMark").getAsInt(), jo.get("lval").getAsInt());
|
transaction.insert(jo.get("traceMark").getAsInt(), jo.get("lval").getAsInt());
|
||||||
|
@ -54,7 +54,7 @@ public class PYEntry {
|
|||||||
pyYjsRequest.setYjsParams(pyYjsParams);
|
pyYjsRequest.setYjsParams(pyYjsParams);
|
||||||
|
|
||||||
response = HttpClient.post(ip, port, urlPath, JsonUtil.toJson(pyYjsRequest));
|
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();
|
return pyResponse.getAsJsonObject("yjsResult").get("objectId").getAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ public class PYEntry {
|
|||||||
|
|
||||||
httpResponse = HttpClient.post(ip, port, urlPath, JsonUtil.toJson(pyYjsRequest));
|
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();
|
return pyResponse.getAsJsonObject("yjsResult").get("objectId").getAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ public class PYEntry {
|
|||||||
String urlPath = "/api/availablePackages/";
|
String urlPath = "/api/availablePackages/";
|
||||||
String response;
|
String response;
|
||||||
response = HttpClient.get(ip, port, urlPath);
|
response = HttpClient.get(ip, port, urlPath);
|
||||||
JsonObject pyResponse = JsonUtil.parseString(response);
|
JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(response);
|
||||||
JsonObject availablePackages =
|
JsonObject availablePackages =
|
||||||
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("availablePackages");
|
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("availablePackages");
|
||||||
JsonArray array = availablePackages.getAsJsonArray("packages");
|
JsonArray array = availablePackages.getAsJsonArray("packages");
|
||||||
@ -98,7 +98,7 @@ public class PYEntry {
|
|||||||
String urlPath = "/api/availableModules/";
|
String urlPath = "/api/availableModules/";
|
||||||
String response;
|
String response;
|
||||||
response = HttpClient.get(ip, port, urlPath);
|
response = HttpClient.get(ip, port, urlPath);
|
||||||
JsonObject pyResponse = JsonUtil.parseString(response);
|
JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(response);
|
||||||
JsonObject availablePackages =
|
JsonObject availablePackages =
|
||||||
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("availableModules");
|
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("availableModules");
|
||||||
JsonArray array = availablePackages.getAsJsonArray("modules");
|
JsonArray array = availablePackages.getAsJsonArray("modules");
|
||||||
@ -125,7 +125,7 @@ public class PYEntry {
|
|||||||
|
|
||||||
// "yjsResult": {"packageTotalInfo": {"package_name": "yjsexample",
|
// "yjsResult": {"packageTotalInfo": {"package_name": "yjsexample",
|
||||||
// "module_names": ["yjsexample.sample"]}}
|
// "module_names": ["yjsexample.sample"]}}
|
||||||
JsonObject pyResponse = JsonUtil.parseString(httpResponse);
|
JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse);
|
||||||
JsonObject packageTotalInfo =
|
JsonObject packageTotalInfo =
|
||||||
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("packageTotalInfo");
|
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("packageTotalInfo");
|
||||||
PackageInfo packageInfo = JsonUtil.fromJson(packageTotalInfo, PackageInfo.class);
|
PackageInfo packageInfo = JsonUtil.fromJson(packageTotalInfo, PackageInfo.class);
|
||||||
@ -161,7 +161,7 @@ public class PYEntry {
|
|||||||
// "sayHello"}, {"func_sign": "(self, name)", "func_name": "sayHello"}],
|
// "sayHello"}, {"func_sign": "(self, name)", "func_name": "sayHello"}],
|
||||||
// "class_name": "A"}
|
// "class_name": "A"}
|
||||||
ModuleInfo moduleInfo;
|
ModuleInfo moduleInfo;
|
||||||
JsonObject pyResponse = JsonUtil.parseString(httpResponse);
|
JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse);
|
||||||
JsonObject moduleInfoObj =
|
JsonObject moduleInfoObj =
|
||||||
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("moduleInfo");
|
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("moduleInfo");
|
||||||
moduleInfo = JsonUtil.fromJson(moduleInfoObj, ModuleInfo.class);
|
moduleInfo = JsonUtil.fromJson(moduleInfoObj, ModuleInfo.class);
|
||||||
@ -230,7 +230,7 @@ public class PYEntry {
|
|||||||
PYClass pyClass = new PYClass();
|
PYClass pyClass = new PYClass();
|
||||||
|
|
||||||
ClassCollection classInfo;
|
ClassCollection classInfo;
|
||||||
JsonObject pyResponse = JsonUtil.parseString(httpResponse);
|
JsonObject pyResponse = JsonUtil.parseStringAsJsonObject(httpResponse);
|
||||||
JsonObject classInfoObj =
|
JsonObject classInfoObj =
|
||||||
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("classInfo");
|
pyResponse.getAsJsonObject("yjsResult").getAsJsonObject("classInfo");
|
||||||
classInfo = JsonUtil.fromJson(classInfoObj, ClassCollection.class);
|
classInfo = JsonUtil.fromJson(classInfoObj, ClassCollection.class);
|
||||||
@ -289,7 +289,7 @@ public class PYEntry {
|
|||||||
pyYjsParams.setParams(PYMethodParams);
|
pyYjsParams.setParams(PYMethodParams);
|
||||||
pyYjsRequest.setYjsParams(pyYjsParams);
|
pyYjsRequest.setYjsParams(pyYjsParams);
|
||||||
httpResponse = HttpClient.post(ip, port, urlPath, 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");
|
JsonObject ysjResult = pyResponse.getAsJsonObject("yjsResult");
|
||||||
return ysjResult.toString();
|
return ysjResult.toString();
|
||||||
}
|
}
|
||||||
@ -308,7 +308,7 @@ public class PYEntry {
|
|||||||
pyYjsParams.setParams(PYMethodParams);
|
pyYjsParams.setParams(PYMethodParams);
|
||||||
pyYjsRequest.setYjsParams(pyYjsParams);
|
pyYjsRequest.setYjsParams(pyYjsParams);
|
||||||
httpResponse = HttpClient.post(ip, port, urlPath, 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");
|
JsonObject ysjResult = pyResponse.getAsJsonObject("yjsResult");
|
||||||
return ysjResult.toString();
|
return ysjResult.toString();
|
||||||
}
|
}
|
||||||
@ -329,7 +329,7 @@ public class PYEntry {
|
|||||||
pyYjsParams.setParams(PYMethodParams);
|
pyYjsParams.setParams(PYMethodParams);
|
||||||
pyYjsRequest.setYjsParams(pyYjsParams);
|
pyYjsRequest.setYjsParams(pyYjsParams);
|
||||||
httpResponse = HttpClient.post(ip, port, urlPath, 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");
|
JsonObject ysjResult = pyResponse.getAsJsonObject("yjsResult");
|
||||||
return ysjResult.toString();
|
return ysjResult.toString();
|
||||||
}
|
}
|
||||||
@ -352,7 +352,7 @@ public class PYEntry {
|
|||||||
pyYjsRequest.setYjsParams(pyYjsParams);
|
pyYjsRequest.setYjsParams(pyYjsParams);
|
||||||
System.out.println(JsonUtil.toJson(pyYjsRequest));
|
System.out.println(JsonUtil.toJson(pyYjsRequest));
|
||||||
httpResponse = HttpClient.post(ip, port, urlPath, 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");
|
JsonObject ysjResult = pyResponse.getAsJsonObject("yjsResult");
|
||||||
return ysjResult.toString();
|
return ysjResult.toString();
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,15 @@ public class JsonUtil {
|
|||||||
return PRETTY_GSON.toJson(o);
|
return PRETTY_GSON.toJson(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject parseString(String json) {
|
public static JsonObject parseStringAsJsonObject(String json) {
|
||||||
return JsonParser.parseString(json).getAsJsonObject();
|
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();
|
return GSON.toJsonTree(obj).getAsJsonObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ public class MultiIndexTimeDBUtil implements MultiIndexTimeDBUtilIntf {
|
|||||||
try {
|
try {
|
||||||
t = db.readFromDatabase(l.toString());
|
t = db.readFromDatabase(l.toString());
|
||||||
if (t != null && !t.isEmpty()) {
|
if (t != null && !t.isEmpty()) {
|
||||||
JsonObject jo = JsonUtil.parseString(t);
|
JsonObject jo = JsonUtil.parseStringAsJsonObject(t);
|
||||||
jo.addProperty("key", l.toString());
|
jo.addProperty("key", l.toString());
|
||||||
ret.add(jo);
|
ret.add(jo);
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ public class MultiIndexTimeDBUtil implements MultiIndexTimeDBUtilIntf {
|
|||||||
String t = db.readFromDatabase(l.toString());
|
String t = db.readFromDatabase(l.toString());
|
||||||
JsonObject jo;
|
JsonObject jo;
|
||||||
if (t != null && !t.isEmpty()) {
|
if (t != null && !t.isEmpty()) {
|
||||||
jo = JsonUtil.parseString(t);
|
jo = JsonUtil.parseStringAsJsonObject(t);
|
||||||
} else {
|
} else {
|
||||||
jo = new JsonObject();
|
jo = new JsonObject();
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public class MultiIndexTimeRocksDBUtil implements MultiIndexTimeDBUtilIntf {
|
|||||||
try {
|
try {
|
||||||
t = new String(db.get(longToByte(l)));
|
t = new String(db.get(longToByte(l)));
|
||||||
if (!t.isEmpty()) {
|
if (!t.isEmpty()) {
|
||||||
JsonObject jo = JsonUtil.parseString(t);
|
JsonObject jo = JsonUtil.parseStringAsJsonObject(t);
|
||||||
jo.addProperty("key", l.toString());
|
jo.addProperty("key", l.toString());
|
||||||
ret.add(jo);
|
ret.add(jo);
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ public class MultiIndexTimeRocksDBUtil implements MultiIndexTimeDBUtilIntf {
|
|||||||
String t = new String(db.get(longToByte(l)));
|
String t = new String(db.get(longToByte(l)));
|
||||||
JsonObject jo;
|
JsonObject jo;
|
||||||
if (!t.isEmpty()) {
|
if (!t.isEmpty()) {
|
||||||
jo = JsonUtil.parseString(t);
|
jo = JsonUtil.parseStringAsJsonObject(t);
|
||||||
} else {
|
} else {
|
||||||
jo = new JsonObject();
|
jo = new JsonObject();
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ public class MultiIndexTimeRocksDBUtil implements MultiIndexTimeDBUtilIntf {
|
|||||||
RocksIterator iter = db.newIterator();
|
RocksIterator iter = db.newIterator();
|
||||||
iter.seekToFirst();
|
iter.seekToFirst();
|
||||||
for (; iter.isValid(); iter.next()) {
|
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();
|
Long time = jo.get("date").getAsLong();
|
||||||
if (time < 0) {
|
if (time < 0) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -134,7 +134,7 @@ public class TimeDBUtil {
|
|||||||
try {
|
try {
|
||||||
String t = db.readFromDatabase(l.toString());
|
String t = db.readFromDatabase(l.toString());
|
||||||
if (null != t && !t.isEmpty()) {
|
if (null != t && !t.isEmpty()) {
|
||||||
JsonObject jo = JsonUtil.parseString(t);
|
JsonObject jo = JsonUtil.parseStringAsJsonObject(t);
|
||||||
jo.addProperty("key", l.toString());
|
jo.addProperty("key", l.toString());
|
||||||
if (jo.has("contractName")
|
if (jo.has("contractName")
|
||||||
&& jo.get("contractName").getAsString().equals(contractName)) {
|
&& jo.get("contractName").getAsString().equals(contractName)) {
|
||||||
@ -293,7 +293,7 @@ public class TimeDBUtil {
|
|||||||
for (Long l : data) {
|
for (Long l : data) {
|
||||||
try {
|
try {
|
||||||
String t = db.readFromDatabase(l.toString());
|
String t = db.readFromDatabase(l.toString());
|
||||||
data2 = JsonUtil.parseString(t);
|
data2 = JsonUtil.parseStringAsJsonObject(t);
|
||||||
ret.add(data2);
|
ret.add(data2);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -323,7 +323,7 @@ public class TimeDBUtil {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
t = db.readFromDatabase(l.toString());
|
t = db.readFromDatabase(l.toString());
|
||||||
data2 = JsonUtil.parseString(t);
|
data2 = JsonUtil.parseStringAsJsonObject(t);
|
||||||
ret.add(data2);
|
ret.add(data2);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("parse json error:" + t);
|
LOGGER.error("parse json error:" + t);
|
||||||
|
@ -145,7 +145,7 @@ public class TimeRocksDBUtil {
|
|||||||
try {
|
try {
|
||||||
String t = new String(db.get(l.toString().getBytes(StandardCharsets.UTF_8)));
|
String t = new String(db.get(l.toString().getBytes(StandardCharsets.UTF_8)));
|
||||||
if (null != t && !t.isEmpty()) {
|
if (null != t && !t.isEmpty()) {
|
||||||
JsonObject jo = JsonUtil.parseString(t);
|
JsonObject jo = JsonUtil.parseStringAsJsonObject(t);
|
||||||
jo.addProperty("key", l.toString());
|
jo.addProperty("key", l.toString());
|
||||||
if (jo.has("contractName")
|
if (jo.has("contractName")
|
||||||
&& jo.get("contractName").getAsString().equals(contractName)) {
|
&& jo.get("contractName").getAsString().equals(contractName)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user