From 2701f7286d2d6c76e43251b254f57b99c34ff652 Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Wed, 17 Nov 2021 14:41:06 +0800 Subject: [PATCH] feat: update usage of JsonUtil --- src/main/java/org/bdware/sc/ContractManager.java | 10 +++++----- src/main/java/org/bdware/sc/event/EventBroker.java | 2 +- src/main/java/org/bdware/sc/event/EventRecorder.java | 4 ++-- .../org/bdware/sc/event/clients/WSClientConsumer.java | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/bdware/sc/ContractManager.java b/src/main/java/org/bdware/sc/ContractManager.java index 209bbca..5a18406 100644 --- a/src/main/java/org/bdware/sc/ContractManager.java +++ b/src/main/java/org/bdware/sc/ContractManager.java @@ -1293,7 +1293,7 @@ public class ContractManager { if (client.contractMeta.sigRequired) { if (!request.verifySignature()) { cr = new ContractResult(Status.Error, new JsonPrimitive("sign verified failed")); - rcb.onResult(JsonUtil.parseObject(cr)); + rcb.onResult(JsonUtil.parseObjectAsJsonObject(cr)); return; } } @@ -1309,7 +1309,7 @@ public class ContractManager { client.traffic += result.length(); client.contractStatus = ContractStatus.Executed; - JsonObject finalRet = JsonUtil.parseString(result); + JsonObject finalRet = JsonUtil.parseStringAsJsonObject(result); if (client.getContractCopies() == 1) { finalRet = extractEventsFromContractResult( @@ -1368,7 +1368,7 @@ public class ContractManager { client.traffic += result.length(); if (client.getContractCopies() == 1) { - extractEventsFromContractResult(ocb, JsonUtil.parseString(result), client, request, start); + extractEventsFromContractResult(ocb, JsonUtil.parseStringAsJsonObject(result), client, request, start); } chainOpener.writeContractResultToLocalAndLedger( result, client, request, ocb, start, System.currentTimeMillis() - start); @@ -1552,7 +1552,7 @@ public class ContractManager { new JsonPrimitive( "Contract " + cr.getContractID() + " doesn't exists!!")); } - rcb.onResult(JsonUtil.parseObject(result)); + rcb.onResult(JsonUtil.parseObjectAsJsonObject(result)); } @@ -2170,7 +2170,7 @@ public class ContractManager { if (null != client) { try { String ret = client.get.syncGet("", "suicide", ""); - JsonObject jo = JsonUtil.parseString(ret); + JsonObject jo = JsonUtil.parseStringAsJsonObject(ret); if (jo.has("cleanSub")) { REvent msg = new REvent( diff --git a/src/main/java/org/bdware/sc/event/EventBroker.java b/src/main/java/org/bdware/sc/event/EventBroker.java index b0dad0c..1c418d6 100644 --- a/src/main/java/org/bdware/sc/event/EventBroker.java +++ b/src/main/java/org/bdware/sc/event/EventBroker.java @@ -265,7 +265,7 @@ public class EventBroker { return null; } try { - JsonObject json = JsonUtil.parseString(content); + JsonObject json = JsonUtil.parseStringAsJsonObject(content); String subscriber = json.get("subscriber").getAsString(); String handler = json.has("handler") ? json.get("handler").getAsString() : null; if (null == subscriber || subscriber.isEmpty()) { diff --git a/src/main/java/org/bdware/sc/event/EventRecorder.java b/src/main/java/org/bdware/sc/event/EventRecorder.java index c89393f..a03c93b 100644 --- a/src/main/java/org/bdware/sc/event/EventRecorder.java +++ b/src/main/java/org/bdware/sc/event/EventRecorder.java @@ -92,7 +92,7 @@ public class EventRecorder { try { if (json.startsWith("cp")) { // create check point by the transaction and stop retrieving - JsonObject data = JsonUtil.parseString(json.substring(2)); + JsonObject data = JsonUtil.parseStringAsJsonObject(json.substring(2)); cp.topic2cIds = JsonUtil.fromJson(data.get("topic2cIds").toString(), topic2cIdsType); JsonObject id2Consumers = data.getAsJsonObject("id2Consumers"); for (String k : id2Consumers.keySet()) { @@ -183,7 +183,7 @@ public class EventRecorder { String json = KeyValueRocksDBUtil.instance.getValue(dbName, TEMP_TOPIC_KEYS); Map ret = new ConcurrentHashMap<>(); try { - JsonObject jo = JsonUtil.parseString(json); + JsonObject jo = JsonUtil.parseStringAsJsonObject(json); for (String key : jo.keySet()) { ret.put(key, jo.get(key).getAsLong()); } diff --git a/src/main/java/org/bdware/sc/event/clients/WSClientConsumer.java b/src/main/java/org/bdware/sc/event/clients/WSClientConsumer.java index 6f6361f..cbca314 100644 --- a/src/main/java/org/bdware/sc/event/clients/WSClientConsumer.java +++ b/src/main/java/org/bdware/sc/event/clients/WSClientConsumer.java @@ -42,7 +42,7 @@ public class WSClientConsumer implements IEventConsumer { JsonObject ret = new JsonObject(); ret.addProperty("action", "onEvent"); ret.addProperty("status", "Success"); - ret.add("data", JsonUtil.parseString(msg)); + ret.add("data", JsonUtil.parseStringAsJsonObject(msg)); channel.writeAndFlush(new TextWebSocketFrame(ret.toString())); }