mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Avoid unchecked casts when deserializing JSON using Gson
This commit is contained in:
parent
09a964ff27
commit
77a8c20ce9
@ -47,16 +47,15 @@ public class FeeProvider extends HttpClientProvider {
|
||||
public Tuple2<Map<String, Long>, Map<String, Long>> getFees() throws IOException {
|
||||
String json = httpClient.requestWithGET("getFees", "User-Agent", "bisq/" + Version.VERSION + ", uid:" + httpClient.getUid());
|
||||
|
||||
LinkedTreeMap<String, Object> linkedTreeMap = new Gson().<LinkedTreeMap<String, Object>>fromJson(json, LinkedTreeMap.class);
|
||||
LinkedTreeMap<?, ?> linkedTreeMap = new Gson().fromJson(json, LinkedTreeMap.class);
|
||||
Map<String, Long> tsMap = new HashMap<>();
|
||||
tsMap.put("bitcoinFeesTs", ((Double) linkedTreeMap.get("bitcoinFeesTs")).longValue());
|
||||
|
||||
Map<String, Long> map = new HashMap<>();
|
||||
|
||||
try {
|
||||
//noinspection unchecked
|
||||
LinkedTreeMap<String, Double> dataMap = (LinkedTreeMap<String, Double>) linkedTreeMap.get("dataMap");
|
||||
Long btcTxFee = dataMap.get("btcTxFee").longValue();
|
||||
LinkedTreeMap<?, ?> dataMap = (LinkedTreeMap<?, ?>) linkedTreeMap.get("dataMap");
|
||||
Long btcTxFee = ((Double) dataMap.get("btcTxFee")).longValue();
|
||||
|
||||
map.put("BTC", btcTxFee);
|
||||
} catch (Throwable t) {
|
||||
|
@ -50,20 +50,20 @@ public class PriceProvider extends HttpClientProvider {
|
||||
String json = httpClient.requestWithGET("getAllMarketPrices", "User-Agent", "bisq/"
|
||||
+ Version.VERSION + ", uid:" + httpClient.getUid());
|
||||
|
||||
LinkedTreeMap<String, Object> map = new Gson().<LinkedTreeMap<String, Object>>fromJson(json, LinkedTreeMap.class);
|
||||
LinkedTreeMap<?, ?> map = new Gson().fromJson(json, LinkedTreeMap.class);
|
||||
Map<String, Long> tsMap = new HashMap<>();
|
||||
tsMap.put("btcAverageTs", ((Double) map.get("btcAverageTs")).longValue());
|
||||
tsMap.put("poloniexTs", ((Double) map.get("poloniexTs")).longValue());
|
||||
tsMap.put("coinmarketcapTs", ((Double) map.get("coinmarketcapTs")).longValue());
|
||||
|
||||
//noinspection unchecked
|
||||
List<LinkedTreeMap<String, Object>> list = (ArrayList<LinkedTreeMap<String, Object>>) map.get("data");
|
||||
list.forEach(treeMap -> {
|
||||
List<?> list = (ArrayList<?>) map.get("data");
|
||||
list.forEach(obj -> {
|
||||
try {
|
||||
LinkedTreeMap<?, ?> treeMap = (LinkedTreeMap<?, ?>) obj;
|
||||
final String currencyCode = (String) treeMap.get("currencyCode");
|
||||
final double price = (double) treeMap.get("price");
|
||||
final double price = (Double) treeMap.get("price");
|
||||
// json uses double for our timestampSec long value...
|
||||
final long timestampSec = MathUtils.doubleToLong((double) treeMap.get("timestampSec"));
|
||||
final long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec"));
|
||||
marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true));
|
||||
} catch (Throwable t) {
|
||||
log.error(t.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user