List of usage examples for com.fasterxml.jackson.databind ObjectMapper readValue
@SuppressWarnings("unchecked") public <T> T readValue(byte[] src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
From source file:com.weavers.duqhan.util.CurrencyConverter.java
public static Double convert(String currencyFrom, String currencyTo) throws IOException { HttpClient httpclient = new DefaultHttpClient(); // HttpGet httpGet = new HttpGet("https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json"); HttpGet httpGet = new HttpGet("https://cdn.shopify.com/s/javascripts/currencies.js"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpGet, responseHandler); httpclient.getConnectionManager().shutdown(); String rates = responseBody.split("rates:")[1].split("convert")[0]; rates = rates.substring(0, rates.length() - 1); ObjectMapper mapper = new ObjectMapper(); CurrencyRates jSONReader = null;//from w w w . j a v a 2 s.c om jSONReader = mapper.readValue(rates, CurrencyRates.class); // System.out.println("ssssssssssss == " + jSONReader.getINR()); double ratio = 0.0; if (currencyTo.equals("USD")) { ratio = jSONReader.getINR() / jSONReader.getUSD(); } else { ratio = jSONReader.getUSD() / jSONReader.getINR(); } return ratio; }
From source file:org.whispersystems.textsecuregcm.limits.LeakyBucket.java
public static LeakyBucket fromSerialized(ObjectMapper mapper, String serialized) throws IOException { LeakyBucketEntity entity = mapper.readValue(serialized, LeakyBucketEntity.class); return new LeakyBucket(entity.bucketSize, entity.leakRatePerMillis, entity.spaceRemaining, entity.lastUpdateTimeMillis); }
From source file:com.boundary.sdk.util.UnixTimeSerializerTest.java
public static MyDate read(String resource) throws URISyntaxException { MyDate instance = new MyDate(); ClassLoader classLoader = instance.getClass().getClassLoader(); URL url = classLoader.getResource(resource); File file = new File(url.toURI()); ObjectMapper mapper = new ObjectMapper(); try {/*from w ww .j a v a 2 s.c o m*/ instance = mapper.readValue(file, MyDate.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return instance; }
From source file:org.camunda.bpm.webapp.impl.security.filter.util.FilterRules.java
public static List<SecurityFilterRule> load(InputStream configFileResource) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); SecurityFilterConfig config = objectMapper.readValue(configFileResource, SecurityFilterConfig.class); return createFilterRules(config); }
From source file:com.ibm.liberty.starter.service.watsonsdk.api.v1.it.EndpointTest.java
@SuppressWarnings("unchecked") public static <T> T testEndpoint(String endpoint, Class<?> entity) throws Exception { String url = getEndPoint(endpoint); System.out.println("Testing " + url); Response response = null;//from w w w .ja va2 s . c om try { response = sendRequest(url, "GET"); int responseCode = response.getStatus(); assertTrue("Incorrect response code for " + url + ": " + responseCode, responseCode == 200); String json = response.readEntity(String.class); ObjectMapper mapper = new ObjectMapper(); return (T) mapper.readValue(json, entity); } finally { if (response != null) { response.close(); } } }
From source file:com.chiralbehaviors.CoRE.loader.Configuration.java
public static Configuration fromYaml(InputStream yaml) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); return mapper.readValue(yaml, Configuration.class); }
From source file:org.schedoscope.metascope.util.SchedoscopeUtil.java
private static ViewStatus getViewStatusFromJson(String json) { ViewStatus viewStatus = null;//from w w w. j av a 2 s . com ObjectMapper objectMapper = new ObjectMapper(); try { viewStatus = objectMapper.readValue(json, ViewStatus.class); } catch (Exception e) { LOG.error("Could not parse JSON from Schedoscope REST API (/). Aborting task execution ...", e); } return viewStatus; }
From source file:org.apache.drill.common.logical.LogicalPlan.java
/** Parses a logical plan. */ public static LogicalPlan parse(DrillConfig config, String planString) { ObjectMapper mapper = config.getMapper(); try {/*from w w w. ja va 2 s . c o m*/ LogicalPlan plan = mapper.readValue(planString, LogicalPlan.class); System.out.println(mapper.writeValueAsString(plan)); return plan; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.jaeksoft.opensearchserver.ServerConfiguration.java
/** * Read the configuration file from the resources * //from www .j av a 2s.co m * @return * @throws JsonParseException * @throws JsonMappingException * @throws IOException */ static ServerConfiguration getDefaultConfiguration() throws JsonParseException, JsonMappingException, IOException { InputStream stream = OpenSearchServer.class.getResourceAsStream("server.yaml"); if (stream == null) throw new IOException("Unable to load the default configuration resource: server.yaml"); try { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); return mapper.readValue(stream, ServerConfiguration.class); } finally { if (stream != null) IOUtils.closeQuietly(stream); } }
From source file:com.mesosphere.sdk.config.SerializationUtils.java
/** * Returns a representation of the provided value using the provided custom object mapper. *//*from ww w .j a va 2 s . c om*/ public static <T> T fromString(String str, Class<T> clazz, ObjectMapper mapper) throws IOException { return mapper.readValue(str, clazz); }