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.lucas.analytics.controller.ml.SearchController.java
public static Search getSearch(String query) throws IOException { ObjectMapper mapper = new ObjectMapper(); String noWhitespace = query.replace(" ", "+"); String targetUrl = baseUrl + "?q=" + StringEscapeUtils.escapeHtml4(noWhitespace) + "&limit=10"; System.out.println("targetUrl: " + targetUrl); return mapper.readValue(Request.Get(targetUrl).execute().returnContent().asString(), Search.class); }
From source file:io.github.retz.scheduler.MesosHTTPFetcher.java
public static Optional<String> extractContainerId(InputStream stream, String frameworkId, String executorId) throws IOException { // { ... "frameworks" : [ { ... "executors":[ { "id":"sum", "completed_tasks":[], "tasks":[], "queued_tasks":[]} ] ... ObjectMapper mapper = new ObjectMapper(); Map<String, Map<String, Object>> map = mapper.readValue(stream, java.util.Map.class); List<Map<String, Object>> list = (List) map.get("frameworks"); // TODO: use json-path for cleaner and flexible code for (Map<String, Object> executors : list) { if (executors.get("executors") != null) { for (Map<String, Object> executor : (List<Map<String, Object>>) executors.get("executors")) { if (executor.get("id").equals(executorId)) { return Optional.ofNullable((String) executor.get("container")); }/*w w w . ja va 2 s . co m*/ } } } return Optional.empty(); }
From source file:io.github.retz.scheduler.MesosHTTPFetcher.java
public static Optional<String> extractDirectory(InputStream stream, String frameworkId, String executorId) throws IOException { // REVIEW: this may prepare corresponded object type instead of using java.util.Map // { ... "frameworks" : [ { ... "executors":[ { "id":"sum", "completed_tasks":[], "tasks":[], "queued_tasks":[]} ] ... ObjectMapper mapper = new ObjectMapper(); Map<String, Map<String, Object>> map = mapper.readValue(stream, java.util.Map.class); List<Map<String, Object>> list = (List) map.get("frameworks"); // TODO: use json-path for cleaner and flexible code for (Map<String, Object> executors : list) { if (executors.get("executors") != null) { for (Map<String, Object> executor : (List<Map<String, Object>>) executors.get("executors")) { if (executor.get("id").equals(executorId)) { return Optional.ofNullable((String) executor.get("directory")); }//w w w. j a v a 2s. co m } } } return Optional.empty(); }
From source file:com.tectonica.thirdparty.Jackson2.java
public static <T> T fromJson(String jsonStr, Class<T> clz, ObjectMapper mapper) { try {/*from w w w .java2s. c o m*/ return mapper.readValue(jsonStr, clz); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.tectonica.thirdparty.Jackson2.java
public static <T> T fromJson(InputStream is, Class<T> clz, ObjectMapper mapper) { try {/*from w w w . j a v a 2 s .c om*/ return mapper.readValue(is, clz); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.tectonica.thirdparty.Jackson2.java
public static <T> T fromJson(Reader r, Class<T> clz, ObjectMapper mapper) { try {/*from w w w .j a v a 2 s . c o m*/ return mapper.readValue(r, clz); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.xeiam.xchange.rest.JSONUtils.java
/** * Get a generic map holding the raw data from the JSON string to allow manual type differentiation * /*from w ww . j a v a 2 s . c om*/ * @param jsonString The JSON string * @param objectMapper The object mapper * @return The map */ public static Map<String, Object> getJsonGenericMap(String jsonString, ObjectMapper objectMapper) { Assert.notNull(jsonString, "jsonString cannot be null"); Assert.notNull(objectMapper, "objectMapper cannot be null"); try { return objectMapper.readValue(jsonString, new TypeReference<Map<String, Object>>() { }); } catch (IOException e) { // Rethrow as runtime exception throw new ExchangeException("Problem getting JSON generic map", e); } }
From source file:com.hurence.logisland.config.ConfigReader.java
/** * Loads a YAML config file//ww w .j a va 2 s.c o m * * @param configFilePath the path of the config file * @return a LogislandSessionConfiguration * @throws Exception */ public static LogislandConfiguration loadConfig(String configFilePath) throws Exception { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); File configFile = new File(configFilePath); if (!configFile.exists()) { throw new FileNotFoundException("Error: File " + configFilePath + " not found!"); } return mapper.readValue(configFile, LogislandConfiguration.class); }
From source file:de.undercouch.bson4jackson.deserializers.BsonDeserializersTest.java
private static <T> T generateAndParse(Object o, Class<T> cls) throws Exception { BSONObject bo = new BasicBSONObject(); bo.put("obj", o); //that's why all properties of classes in TC must be named 'obj' BSONEncoder encoder = new BasicBSONEncoder(); byte[] barr = encoder.encode(bo); ByteArrayInputStream bais = new ByteArrayInputStream(barr); ObjectMapper om = new ObjectMapper(new BsonFactory()); om.registerModule(new BsonModule()); T r = om.readValue(bais, cls); return r;//from ww w . j a v a 2 s . c o m }
From source file:com.appdynamics.extensions.solr.SolrHelper.java
public static JsonNode getJsonNode(InputStream inputStream) throws IOException { if (inputStream == null) { return null; }//www. ja va2 s . c o m ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(inputStream, JsonNode.class); }