From c71d9802ba52022bd35dc29dd76dae820d7c9a8d Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Wed, 6 Jun 2018 10:50:14 -0500 Subject: [PATCH] Correctly deserializing the GetRequiredFees API call's response --- .../graphenej/api/android/DeserializationMap.java | 13 ++++++++----- .../graphenej/api/android/NetworkService.java | 6 ++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java index 4cd85e8..cdb6c2d 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/DeserializationMap.java @@ -1,12 +1,10 @@ package cy.agorise.graphenej.api.android; -import com.google.common.reflect.TypeToken; import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import java.lang.reflect.Type; import java.util.HashMap; import java.util.List; @@ -16,7 +14,7 @@ import cy.agorise.graphenej.Authority; import cy.agorise.graphenej.Transaction; import cy.agorise.graphenej.api.calls.GetAccounts; import cy.agorise.graphenej.api.calls.GetBlock; -import cy.agorise.graphenej.models.AccountProperties; +import cy.agorise.graphenej.api.calls.GetRequiredFees; import cy.agorise.graphenej.models.Block; import cy.agorise.graphenej.operations.CustomOperation; import cy.agorise.graphenej.operations.LimitOrderCreateOperation; @@ -48,8 +46,6 @@ public class DeserializationMap { mGsonMap.put(GetBlock.class, getBlockGson); // GetAccounts - Type GetAccountResponse = new TypeToken>() {}.getType(); - mClassMap.put(GetAccounts.class, GetAccountResponse.getClass()); mClassMap.put(GetAccounts.class, List.class); Gson getAccountsGson = new GsonBuilder() .setExclusionStrategies(new GetAccountsExclusionStrategy()) @@ -57,6 +53,13 @@ public class DeserializationMap { .registerTypeAdapter(AccountOptions.class, new AccountOptions.AccountOptionsDeserializer()) .create(); mGsonMap.put(GetAccounts.class, getAccountsGson); + + // GetRequiredFees + mClassMap.put(GetRequiredFees.class, List.class); + Gson getRequiredFeesGson = new GsonBuilder() + .registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetAmountDeserializer()) + .create(); + mGsonMap.put(GetRequiredFees.class, getRequiredFeesGson); } public Class getReceivedClass(Class _class){ diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java index bccfa8e..d7b8cd9 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java @@ -17,12 +17,14 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import cy.agorise.graphenej.AssetAmount; import cy.agorise.graphenej.RPC; import cy.agorise.graphenej.api.ApiAccess; import cy.agorise.graphenej.api.ConnectionStatusUpdate; import cy.agorise.graphenej.api.bitshares.Nodes; import cy.agorise.graphenej.api.calls.ApiCallable; import cy.agorise.graphenej.api.calls.GetAccounts; +import cy.agorise.graphenej.api.calls.GetRequiredFees; import cy.agorise.graphenej.models.AccountProperties; import cy.agorise.graphenej.models.ApiCall; import cy.agorise.graphenej.models.Block; @@ -284,6 +286,10 @@ public class NetworkService extends Service { Type GetAccountsResponse = new TypeToken>>(){}.getType(); JsonRpcResponse> accountResponse = (JsonRpcResponse) gson.fromJson(text, GetAccountsResponse); parsedResponse = accountResponse; + }else if(requestClass == GetRequiredFees.class){ + Type GetRequiredFeesResponse = new TypeToken>>(){}.getType(); + JsonRpcResponse> assetAmountResponse = (JsonRpcResponse) gson.fromJson(text, GetRequiredFeesResponse); + parsedResponse = assetAmountResponse; }else{ Log.w(TAG,"Unknown request class"); }