use of com.google.gson.internal.LinkedTreeMap in project ff4j by ff4j.
the class FeatureConverter method deserialize.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Feature deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
String uid = json.getAsJsonObject().get("uid").getAsString();
Feature feature = new Feature(uid);
// Property "enable"
JsonElement enable = json.getAsJsonObject().get("enable");
if (enable != null) {
feature.setEnable(enable.getAsBoolean());
}
// Description
JsonElement description = json.getAsJsonObject().get("description");
if (description != null) {
feature.setDescription(description.getAsString());
}
// Group
JsonElement group = json.getAsJsonObject().get("group");
if (group != null) {
feature.setGroup(group.getAsString());
}
// Permissions
JsonElement permissions = json.getAsJsonObject().get("permissions");
if (permissions != null) {
Set<String> auths = gson.fromJson(permissions, new TypeToken<HashSet<String>>() {
}.getType());
feature.setPermissions(auths);
}
// Flipping strategy
JsonElement flippingStrategy = json.getAsJsonObject().get("flippingStrategy");
if (flippingStrategy != null && !flippingStrategy.isJsonNull()) {
Map<String, ?> flippingStrategyParameters = gson.fromJson(flippingStrategy, new TypeToken<HashMap<String, ?>>() {
}.getType());
String flippingStrategyType = flippingStrategyParameters.get("type").toString();
Map<String, String> initParams = (Map<String, String>) flippingStrategyParameters.get("initParams");
// Adding flipping strategy
feature.setFlippingStrategy(MappingUtil.instanceFlippingStrategy(uid, flippingStrategyType, initParams));
}
// Custom properties
JsonElement customProperties = json.getAsJsonObject().get("customProperties");
if (customProperties != null && !customProperties.isJsonNull()) {
Map<String, LinkedTreeMap<String, Object>> map = new Gson().fromJson(customProperties, new TypeToken<com.google.gson.internal.LinkedTreeMap<String, LinkedTreeMap<String, Object>>>() {
}.getType());
for (Entry<String, LinkedTreeMap<String, Object>> element : map.entrySet()) {
LinkedTreeMap<String, Object> propertyValues = element.getValue();
// Getting values
String pName = (String) propertyValues.get("name");
String pType = (String) propertyValues.get("type");
String pValue = (String) propertyValues.get("value");
String desc = (String) propertyValues.get("description");
Object fixedValues = propertyValues.get("fixedValues");
Set pFixedValues = fixedValues != null ? new HashSet((Collection) fixedValues) : null;
// Creating property with it
Property<?> property = PropertyFactory.createProperty(pName, pType, pValue, desc, pFixedValues);
feature.addProperty(property);
}
}
return feature;
}
use of com.google.gson.internal.LinkedTreeMap in project bisq-core by bisq-network.
the class FeeProvider method getFees.
public Tuple2<Map<String, Long>, Map<String, Long>> getFees() throws IOException {
String json = httpClient.requestWithGET("getFees", "User-Agent", "bisq/" + Version.VERSION + ", uid:" + httpClient.getUid());
// noinspection unchecked
LinkedTreeMap<String, Object> 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();
Long ltcTxFee = dataMap.get("ltcTxFee").longValue();
Long dashTxFee = dataMap.get("dashTxFee").longValue();
map.put("BTC", btcTxFee);
map.put("LTC", ltcTxFee);
map.put("DASH", dashTxFee);
} catch (Throwable t) {
log.error(t.toString());
t.printStackTrace();
}
return new Tuple2<>(tsMap, map);
}
use of com.google.gson.internal.LinkedTreeMap in project bisq-core by bisq-network.
the class PriceProvider method getAll.
public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOException {
Map<String, MarketPrice> marketPriceMap = new HashMap<>();
String json = httpClient.requestWithGET("getAllMarketPrices", "User-Agent", "bisq/" + Version.VERSION + ", uid:" + httpClient.getUid());
// noinspection unchecked
LinkedTreeMap<String, Object> 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 -> {
try {
final String currencyCode = (String) treeMap.get("currencyCode");
final double price = (double) treeMap.get("price");
// json uses double for our timestampSec long value...
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());
t.printStackTrace();
}
});
return new Tuple2<>(tsMap, marketPriceMap);
}
use of com.google.gson.internal.LinkedTreeMap in project components by Talend.
the class MarketoBaseRESTClient method executePostRequest.
public MarketoRecordResult executePostRequest(JsonObject inputJson) throws MarketoException {
try {
URL url = new URL(current_uri.toString());
HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
urlConn.setRequestMethod("POST");
// "application/json"
urlConn.setRequestProperty(REQUEST_PROPERTY_CONTENT_TYPE, REQUEST_VALUE_APPLICATION_JSON);
// content-type is
// required.
urlConn.setRequestProperty(REQUEST_PROPERTY_ACCEPT, REQUEST_VALUE_TEXT_JSON);
urlConn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream());
wr.write(inputJson.toString());
wr.flush();
wr.close();
int responseCode = urlConn.getResponseCode();
if (responseCode == 200) {
InputStream inStream = urlConn.getInputStream();
InputStreamReader reader = new InputStreamReader(inStream);
Gson gson = new Gson();
LinkedTreeMap ltm = (LinkedTreeMap) gson.fromJson(reader, Object.class);
MarketoRecordResult mkr = new MarketoRecordResult();
mkr.setRequestId(REST + "::" + ltm.get("requestId"));
mkr.setSuccess(Boolean.parseBoolean(ltm.get("success").toString()));
return mkr;
} else {
LOG.error("POST request failed: {}", responseCode);
throw new MarketoException(REST, responseCode, "Request failed! Please check your request setting!");
}
} catch (IOException e) {
LOG.error("GET request failed: {}", e.getMessage());
throw new MarketoException(REST, e.getMessage());
}
}
use of com.google.gson.internal.LinkedTreeMap in project components by Talend.
the class MarketoBaseRESTClient method getToken.
public void getToken() throws MarketoException {
try {
URL basicURI = new URL(endpoint);
current_uri = //
new StringBuilder(basicURI.getProtocol()).append(//
"://").append(//
basicURI.getHost()).append(//
API_PATH_IDENTITY_OAUTH_TOKEN).append(//
fmtParams("client_id", userId)).append(fmtParams("client_secret", secretKey));
URL url = new URL(current_uri.toString());
HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
urlConn.setRequestMethod("GET");
urlConn.setRequestProperty(REQUEST_PROPERTY_ACCEPT, REQUEST_VALUE_APPLICATION_JSON);
int responseCode = urlConn.getResponseCode();
if (responseCode == 200) {
InputStream inStream = urlConn.getInputStream();
Reader reader = new InputStreamReader(inStream);
Gson gson = new Gson();
LinkedTreeMap js = (LinkedTreeMap) gson.fromJson(reader, Object.class);
Object ac = js.get("access_token");
if (ac != null) {
accessToken = ac.toString();
LOG.debug("MarketoRestExecutor.getAccessToken GOT token");
} else {
LinkedTreeMap err = (LinkedTreeMap) ((ArrayList) js.get(FIELD_ERRORS)).get(0);
throw new MarketoException(REST, err.get("code").toString(), err.get("message").toString());
}
} else {
throw new MarketoException(REST, responseCode, "Marketo Authentication failed! Please check your " + "setting!");
}
} catch (ProtocolException | SocketTimeoutException | SocketException e) {
LOG.error("AccessToken error: {}.", e.getMessage());
throw new MarketoException(REST, "Marketo Authentication failed : " + e.getMessage());
} catch (IOException e) {
LOG.error("AccessToken error: {}.", e.getMessage());
throw new MarketoException(REST, "Marketo Authentication failed : " + e.getMessage());
}
}
Aggregations