@Test public void testDeserialize() { TransactionResponse transaction = GsonSingleton.getInstance().fromJson(json, TransactionResponse.class); assertEquals(transaction.getHash(), "5c2e4dad596941ef944d72741c8f8f1a4282f8f2f141e81d827f44bf365d626b"); assertEquals(transaction.getLedger(), new Long(915744)); assertEquals(transaction.getCreatedAt(), "2015-11-20T17:01:28Z"); assertEquals(transaction.getPagingToken(), "3933090531512320"); assertEquals(transaction.getSourceAccount().getAccountId(), "GCUB7JL4APK7LKJ6MZF7Q2JTLHAGNBIUA7XIXD5SQTG52GQ2DAT6XZMK"); assertEquals(transaction.getSourceAccountSequence(), new Long(2373051035426646L)); assertEquals(transaction.getFeePaid(), new Long(100)); assertEquals(transaction.getOperationCount(), new Integer(1)); assertEquals(transaction.getEnvelopeXdr(), "AAAAAKgfpXwD1fWpPmZL+GkzWcBmhRQH7ouPsoTN3RoaGCfrAAAAZAAIbkcAAB9WAAAAAAAAAANRBBZE6D1qyGjISUGLY5Ldvp31PwAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAP1qe44j+i4uIT+arbD4QDQBt8ryEeJd7a0jskQ3nwDeAAAAAAAAAADA7RnarSzCwj3OT+M2btCMFpVBdqxJS+Sr00qBjtFv7gAAAABLCs/QAAAAAAAAAAEaGCfrAAAAQG/56Cj2J8W/KCZr+oC4sWND1CTGWfaccHNtuibQH8kZIb+qBSDY94g7hiaAXrlIeg9b7oz/XuP3x9MWYw2jtwM="); assertEquals(transaction.getResultXdr(), "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA="); assertEquals(transaction.getResultMetaXdr(), "AAAAAAAAAAEAAAACAAAAAAAN+SAAAAAAAAAAAMDtGdqtLMLCPc5P4zZu0IwWlUF2rElL5KvTSoGO0W/uAAAAAEsKz9AADfkgAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAQAN+SAAAAAAAAAAAP1qe44j+i4uIT+arbD4QDQBt8ryEeJd7a0jskQ3nwDeAAHp6WMr55YACD1BAAAAHgAAAAoAAAAAAAAAAAAAAAABAAAAAAAACgAAAAARC07BokpLTOF+/vVKBwiAlop7hHGJTNeGGlY4MoPykwAAAAEAAAAAK+Lzfd3yDD+Ov0GbYu1g7SaIBrKZeBUxoCunkLuI7aoAAAABAAAAAERmsKL73CyLV/HvjyQCERDXXpWE70Xhyb6MR5qPO3yQAAAAAQAAAABSORGwAdyuanN3sNOHqNSpACyYdkUM3L8VafUu69EvEgAAAAEAAAAAeCzqJNkMM/jLvyuMIfyFHljBlLCtDyj17RMycPuNtRMAAAABAAAAAIEi4R7juq15ymL00DNlAddunyFT4FyUD4muC4t3bobdAAAAAQAAAACaNpLL5YMfjOTdXVEqrAh99LM12sN6He6pHgCRAa1f1QAAAAEAAAAAqB+lfAPV9ak+Zkv4aTNZwGaFFAfui4+yhM3dGhoYJ+sAAAABAAAAAMNJrEvdMg6M+M+n4BDIdzsVSj/ZI9SvAp7mOOsvAD/WAAAAAQAAAADbHA6xiKB1+G79mVqpsHMOleOqKa5mxDpP5KEp/Xdz9wAAAAEAAAAAAAAAAA=="); List<Operation> operations = transaction.getOperations(); assertNotNull(operations); assertEquals(operations.size(), 1); assertTrue(operations.get(0) instanceof CreateAccountOperation); CreateAccountOperation createAccountOperation = (CreateAccountOperation) operations.get(0); assertEquals(createAccountOperation.getSourceAccount().getAccountId(), "GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD"); assertEquals(createAccountOperation.getDestination().getAccountId(), "GDAO2GO2VUWMFQR5ZZH6GNTO2CGBNFKBO2WESS7EVPJUVAMO2FX64V4B"); assertTrue(transaction.getMemo() instanceof MemoHash); MemoHash memo = (MemoHash) transaction.getMemo(); assertEquals("51041644e83d6ac868c849418b6392ddbe9df53f000000000000000000000000", memo.getHexValue()); assertEquals(transaction.getLinks().getAccount().getHref(), "/accounts/GCUB7JL4APK7LKJ6MZF7Q2JTLHAGNBIUA7XIXD5SQTG52GQ2DAT6XZMK"); assertEquals(transaction.getLinks().getEffects().getHref(), "/transactions/5c2e4dad596941ef944d72741c8f8f1a4282f8f2f141e81d827f44bf365d626b/effects{?cursor,limit,order}"); assertEquals(transaction.getLinks().getLedger().getHref(), "/ledgers/915744"); assertEquals(transaction.getLinks().getOperations().getHref(), "/transactions/5c2e4dad596941ef944d72741c8f8f1a4282f8f2f141e81d827f44bf365d626b/operations{?cursor,limit,order}"); assertEquals(transaction.getLinks().getPrecedes().getHref(), "/transactions?cursor=3933090531512320&order=asc"); assertEquals(transaction.getLinks().getSelf().getHref(), "/transactions/5c2e4dad596941ef944d72741c8f8f1a4282f8f2f141e81d827f44bf365d626b"); assertEquals(transaction.getLinks().getSucceeds().getHref(), "/transactions?cursor=3933090531512320&order=desc"); }
@Override public TransactionResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Gson gson = new GsonBuilder() .registerTypeAdapter(KeyPair.class, new KeyPairTypeAdapter().nullSafe()) .create(); TransactionResponse transaction = gson.fromJson(json, TransactionResponse.class); String memoType = json.getAsJsonObject().get("memo_type").getAsString(); Memo memo; if (memoType.equals("none")) { memo = Memo.none(); } else { if (memoType.equals("text")) { JsonElement memoField = json.getAsJsonObject().get("memo"); if (memoField != null) { memo = Memo.text(memoField.getAsString()); } else { memo = Memo.text(""); } } else { String memoValue = json.getAsJsonObject().get("memo").getAsString(); if (memoType.equals("id")) { memo = Memo.id(Long.parseLong(memoValue)); } else if (memoType.equals("hash")) { memo = Memo.hash(Base64.decodeBase64(memoValue)); } else if (memoType.equals("return")) { memo = Memo.returnHash(Base64.decodeBase64(memoValue)); } else { throw new JsonParseException("Unknown memo type."); } } } transaction.setMemo(memo); return transaction; }
TransactionDeserializer implements JsonDeserializer<TransactionResponse> { @Override public TransactionResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Gson gson = new GsonBuilder() .registerTypeAdapter(KeyPair.class, new KeyPairTypeAdapter().nullSafe()) .create(); TransactionResponse transaction = gson.fromJson(json, TransactionResponse.class); String memoType = json.getAsJsonObject().get("memo_type").getAsString(); Memo memo; if (memoType.equals("none")) { memo = Memo.none(); } else { if (memoType.equals("text")) { JsonElement memoField = json.getAsJsonObject().get("memo"); if (memoField != null) { memo = Memo.text(memoField.getAsString()); } else { memo = Memo.text(""); } } else { String memoValue = json.getAsJsonObject().get("memo").getAsString(); if (memoType.equals("id")) { memo = Memo.id(Long.parseLong(memoValue)); } else if (memoType.equals("hash")) { memo = Memo.hash(Base64.decodeBase64(memoValue)); } else if (memoType.equals("return")) { memo = Memo.returnHash(Base64.decodeBase64(memoValue)); } else { throw new JsonParseException("Unknown memo type."); } } } transaction.setMemo(memo); return transaction; } }
TransactionDeserializer implements JsonDeserializer<TransactionResponse> { @Override public TransactionResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Gson gson = new GsonBuilder() .registerTypeAdapter(KeyPair.class, new KeyPairTypeAdapter().nullSafe()) .create(); TransactionResponse transaction = gson.fromJson(json, TransactionResponse.class); String memoType = json.getAsJsonObject().get("memo_type").getAsString(); Memo memo; if (memoType.equals("none")) { memo = Memo.none(); } else { if (memoType.equals("text")) { JsonElement memoField = json.getAsJsonObject().get("memo"); if (memoField != null) { memo = Memo.text(memoField.getAsString()); } else { memo = Memo.text(""); } } else { String memoValue = json.getAsJsonObject().get("memo").getAsString(); if (memoType.equals("id")) { memo = Memo.id(Long.parseLong(memoValue)); } else if (memoType.equals("hash")) { memo = Memo.hash(Base64.decodeBase64(memoValue)); } else if (memoType.equals("return")) { memo = Memo.returnHash(Base64.decodeBase64(memoValue)); } else { throw new JsonParseException("Unknown memo type."); } } } transaction.setMemo(memo); return transaction; }  }
TransactionDeserializer implements JsonDeserializer<TransactionResponse> { @Override public TransactionResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Gson gson = new GsonBuilder() .registerTypeAdapter(KeyPair.class, new KeyPairTypeAdapter().nullSafe()) .create(); TransactionResponse transaction = gson.fromJson(json, TransactionResponse.class); String memoType = json.getAsJsonObject().get("memo_type").getAsString(); Memo memo; if (memoType.equals("none")) { memo = Memo.none(); } else { if (memoType.equals("text")) { JsonElement memoField = json.getAsJsonObject().get("memo"); if (memoField != null) { memo = Memo.text(memoField.getAsString()); } else { memo = Memo.text(""); } } else { String memoValue = json.getAsJsonObject().get("memo").getAsString(); if (memoType.equals("id")) { memo = Memo.id(Long.parseLong(memoValue)); } else if (memoType.equals("hash")) { memo = Memo.hash(Base64.decodeBase64(memoValue)); } else if (memoType.equals("return")) { memo = Memo.returnHash(Base64.decodeBase64(memoValue)); } else { throw new JsonParseException("Unknown memo type."); } } } transaction.setMemo(memo); return transaction; }  @Override TransactionResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context); }
TransactionDeserializer implements JsonDeserializer<TransactionResponse> { @Override public TransactionResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Gson gson = new GsonBuilder() .registerTypeAdapter(KeyPair.class, new KeyPairTypeAdapter().nullSafe()) .create(); TransactionResponse transaction = gson.fromJson(json, TransactionResponse.class); String memoType = json.getAsJsonObject().get("memo_type").getAsString(); Memo memo; if (memoType.equals("none")) { memo = Memo.none(); } else { if (memoType.equals("text")) { JsonElement memoField = json.getAsJsonObject().get("memo"); if (memoField != null) { memo = Memo.text(memoField.getAsString()); } else { memo = Memo.text(""); } } else { String memoValue = json.getAsJsonObject().get("memo").getAsString(); if (memoType.equals("id")) { memo = Memo.id(Long.parseLong(memoValue)); } else if (memoType.equals("hash")) { memo = Memo.hash(Base64.decodeBase64(memoValue)); } else if (memoType.equals("return")) { memo = Memo.returnHash(Base64.decodeBase64(memoValue)); } else { throw new JsonParseException("Unknown memo type."); } } } transaction.setMemo(memo); return transaction; }  @Override TransactionResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context);  }