diff --git a/src/main/java/iost/Client.java b/src/main/java/iost/Client.java index 8af72fc..72a2317 100644 --- a/src/main/java/iost/Client.java +++ b/src/main/java/iost/Client.java @@ -1,7 +1,6 @@ package iost; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import com.google.gson.*; import iost.model.account.*; import iost.model.block.*; import iost.model.info.*; @@ -10,6 +9,7 @@ import java.io.IOException; import java.util.Date; +import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeoutException; @@ -36,6 +36,7 @@ public Client(String url) { this.client = new OkHttpClient(); GsonBuilder gb = new GsonBuilder(); gb.registerTypeAdapter(Signature.class, new SignatureAdapter()); + gb.registerTypeAdapter(BigDecimal.class, (JsonSerializer) (src, typeOfSrc, context) -> new JsonPrimitive(src.toPlainString())); this.gson = gb.create(); } diff --git a/src/main/java/iost/IOST.java b/src/main/java/iost/IOST.java index ceb2940..1e7cea1 100644 --- a/src/main/java/iost/IOST.java +++ b/src/main/java/iost/IOST.java @@ -63,8 +63,8 @@ public Transaction callABI(String cid, String abi, Object... data) { * @return - */ public Transaction transfer(String token, String from, String to, BigDecimal amount, String memo) { - Transaction tx = this.callABI("token.iost", "transfer", token, from, to, amount.toString(), memo); - tx.addApprove(token, amount.toString()); + Transaction tx = this.callABI("token.iost", "transfer", token, from, to, amount.stripTrailingZeros().toPlainString(), memo); + tx.addApprove(token, amount.stripTrailingZeros().toPlainString()); return tx; }