From 1d3efbdb97a2b658df7dfc1690e51d0804a6dbaf Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Thu, 7 Apr 2022 18:49:57 +0800 Subject: [PATCH] support serialzable json --- .../entry/org/bdware/sc/bean/Contract.java | 7 +++--- .../org/bdware/sc/bean/SerializableJson.java | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/main/entry/org/bdware/sc/bean/SerializableJson.java diff --git a/src/main/entry/org/bdware/sc/bean/Contract.java b/src/main/entry/org/bdware/sc/bean/Contract.java index 3cbb86e..b79e35a 100644 --- a/src/main/entry/org/bdware/sc/bean/Contract.java +++ b/src/main/entry/org/bdware/sc/bean/Contract.java @@ -39,7 +39,8 @@ public class Contract extends SM2Verifiable implements Serializable { private String hash; private boolean stateful = true; // manifest可配置 private YjsType yjsType; - private JsonElement createParam; + + private SerializableJson createParam; public int getShardingId() { return this.shardingId; @@ -228,10 +229,10 @@ public class Contract extends SM2Verifiable implements Serializable { } public void setCreateParam(JsonElement ele) { - createParam = ele; + createParam = new SerializableJson(ele); } public JsonElement getCreateParam() { - return createParam; + return createParam.getJsonElement(); } } diff --git a/src/main/entry/org/bdware/sc/bean/SerializableJson.java b/src/main/entry/org/bdware/sc/bean/SerializableJson.java new file mode 100644 index 0000000..0c7b3da --- /dev/null +++ b/src/main/entry/org/bdware/sc/bean/SerializableJson.java @@ -0,0 +1,25 @@ +package org.bdware.sc.bean; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; + +import java.io.Serializable; + +public class SerializableJson implements Serializable { + transient JsonElement jsonElement; + String content; + + public SerializableJson(JsonElement jsonElement) { + this.jsonElement = jsonElement; + if (jsonElement != null) + content = jsonElement.toString(); + } + + public JsonElement getJsonElement() { + if (jsonElement != null) + return jsonElement; + if (content != null) + return JsonParser.parseString(content); + return null; + } +}