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:Main.java
public static String getValueFromJson(String json, String key) { String value = "null"; try {//from ww w. jav a2 s . co m ObjectMapper mapper = new ObjectMapper(); Map<String, Object> values = mapper.readValue(json, new TypeReference<Map<String, String>>() { }); if (values.containsKey(key)) { value = values.get(key).toString(); } } catch (IOException e) { System.out.println("Could not parse json: " + json); } return value; }
From source file:com.shampan.db.collections.fragment.user.Group.java
public static Group getGroup(String jsonContent) { Group groupInfo = null;/*from w ww. j a v a 2 s .co m*/ try { ObjectMapper mapper = new ObjectMapper(); groupInfo = mapper.readValue(jsonContent, Group.class); } catch (Exception ex) { ex.printStackTrace(); } return groupInfo; }
From source file:org.hawkular.client.test.utils.JSONHelper.java
public static <T> T load(Class<T> clz, File jsonFile) { ObjectMapper mapper = new ObjectMapper(); try {//from w w w . j a v a 2s.c o m return mapper.readValue(jsonFile, clz); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.solr.kelvin.testcases.SimpleConditionTest.java
public static JsonNode readJsonResource(Class<?> c, String resourceName) throws IOException { String raw = IOUtils.toString(c.getResourceAsStream(resourceName), "utf8"); ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(raw, JsonNode.class); }
From source file:org.hawkular.client.test.utils.JSONHelper.java
public static <T> T load(Class<T> clz, String jsonFile) { InputStream is = JSONHelper.class.getResourceAsStream(jsonFile); if (is == null) { throw new RuntimeException("Can't load " + jsonFile); }/*w ww . ja v a 2s . c om*/ ObjectMapper mapper = new ObjectMapper(); try { return mapper.readValue(is, clz); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.shampan.db.collections.fragment.profile.City.java
public static City getCurrentCity(String jsonContent) { City city = null;//w ww . j a v a 2 s. com try { ObjectMapper mapper = new ObjectMapper(); city = mapper.readValue(jsonContent, City.class); } catch (Exception ex) { ex.printStackTrace(); } return city; }
From source file:com.shampan.db.collections.fragment.profile.Town.java
public static Town getHomeTown(String jsonContent) { Town town = null;/*from w ww. ja v a 2 s . com*/ try { ObjectMapper mapper = new ObjectMapper(); town = mapper.readValue(jsonContent, Town.class); } catch (Exception ex) { ex.printStackTrace(); } return town; }
From source file:com.massivcode.weatherinfoexam.utils.NetworkUtil.java
public static Forecast parseJsonToForecastInfo(String jsonString) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); Forecast forecast = objectMapper.readValue(jsonString, Forecast.class); return forecast; }
From source file:com.shampan.db.collections.fragment.user.Country.java
public static Country getCountryInfo(String jsonContent) { Country countryInfo = null;/*from w ww. j a va 2 s. c o m*/ try { ObjectMapper mapper = new ObjectMapper(); countryInfo = mapper.readValue(jsonContent, Country.class); } catch (Exception ex) { ex.printStackTrace(); } return countryInfo; }
From source file:xyz.monotalk.social.mixcloud.internal.JsonUtils.java
/** * readValue//from ww w. j a v a 2 s. c om * * @param <T> * @param json * @param clazz * @return */ public static <T> T readValue(String json, Class<T> clazz) { T result = null; try { ObjectMapper mapper = new ObjectMapper(); result = mapper.readValue(json, clazz); } catch (IOException ex) { throw new RuntimeException(ex); } return result; }