Example usage for com.fasterxml.jackson.databind ObjectReader treeToValue

List of usage examples for com.fasterxml.jackson.databind ObjectReader treeToValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectReader treeToValue.

Prototype

@Override
    public <T> T treeToValue(TreeNode n, Class<T> valueType) throws JsonProcessingException 

Source Link

Usage

From source file:com.erudika.para.i18n.OXRCurrencyConverter.java

@SuppressWarnings("unchecked")
private Sysprop fetchFxRatesJSON() {
    Map<String, Object> map = new HashMap<String, Object>();
    Sysprop s = new Sysprop();
    ObjectReader reader = ParaObjectUtils.getJsonReader(Map.class);

    try {//from www  . j  av  a2s.co  m
        CloseableHttpClient http = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(SERVICE_URL);
        HttpResponse res = http.execute(httpGet);
        HttpEntity entity = res.getEntity();

        if (entity != null && Utils.isJsonType(entity.getContentType().getValue())) {
            JsonNode jsonNode = reader.readTree(entity.getContent());
            if (jsonNode != null) {
                JsonNode rates = jsonNode.get("rates");
                if (rates != null) {
                    map = reader.treeToValue(rates, Map.class);
                    s.setId(FXRATES_KEY);
                    s.setProperties(map);
                    //                  s.addProperty("fetched", Utils.formatDate("dd MM yyyy HH:mm", Locale.UK));
                    dao.create(s);
                }
            }
            EntityUtils.consume(entity);
        }
        logger.debug("Fetched rates from OpenExchange for {}.", new Date().toString());
    } catch (Exception e) {
        logger.error("TimerTask failed: {}", e);
    }
    return s;
}