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:AIR.Common.Json.JsonHelper.java
public static <T> T deserialize(String json, Class<T> class1) throws JsonParseException, JsonMappingException, IOException { if (StringUtils.isEmpty(json)) return null; ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(json, class1); }
From source file:com.proofpoint.event.client.TestingUtils.java
public static String getNormalizedJson(String resource) throws IOException { String json = Resources.toString(Resources.getResource(resource), Charsets.UTF_8); ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(mapper.readValue(json, Object.class)); }
From source file:com.lixiaocong.util.weather.WeatherHelper.java
public static Weather getWeather(String city) throws IOException { HttpClient httpClient = HttpClients.custom().build(); HttpGet httpGet = new HttpGet("http://apis.baidu.com/apistore/weatherservice/weather?citypinyin=" + city); httpGet.addHeader("apikey", "f6e1b7c306d087df20761632655bc18b"); RequestConfig config = RequestConfig.custom().setConnectTimeout(500).build(); httpGet.setConfig(config);//from w w w .j ava 2s . c o m HttpResponse response = httpClient.execute(httpGet); String jsonString = EntityUtils.toString(response.getEntity()); logger.info("weather server returns " + jsonString); ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(jsonString, Weather.class); }
From source file:com.shampan.db.collections.fragment.page.AgeRange.java
public static AgeRange getUserInformation(String jsonContent) { AgeRange ageInfo = null;//from w ww .j a v a 2 s . c o m try { ObjectMapper mapper = new ObjectMapper(); ageInfo = mapper.readValue(jsonContent, AgeRange.class); } catch (Exception ex) { ex.printStackTrace(); } return ageInfo; }
From source file:com.shampan.db.collections.fragment.profile.Religion.java
public static Religion getReligionInfo(String jsonContent) { Religion religion = null;/*from w ww.j av a 2 s.co m*/ try { ObjectMapper mapper = new ObjectMapper(); religion = mapper.readValue(jsonContent, Religion.class); } catch (Exception ex) { ex.printStackTrace(); } return religion; }
From source file:com.pacoworks.cardframework.api.factories.system.SystemFactory.java
public static BasePhaseSystem create(CardgameFramework.CardgameFrameworkComponent injector, @NonNull URL filePath) throws IOException { ObjectMapper mapper = new ObjectMapper(); CFWSystem cfwSystem = mapper.readValue(filePath, CFWSystem.class); return create(injector, cfwSystem); }
From source file:com.pacoworks.cardframework.api.factories.system.SystemFactory.java
public static BasePhaseSystem create(CardgameFramework.CardgameFrameworkComponent injector, @NonNull File file) throws IOException { ObjectMapper mapper = new ObjectMapper(); CFWSystem cfwSystem = mapper.readValue(file, CFWSystem.class); return create(injector, cfwSystem); }
From source file:com.shampan.db.collections.fragment.common.Like.java
public static Like getLikeInfo(String jsonContent) { Like likeInfo = null;// w w w . jav a 2s . c o m try { ObjectMapper mapper = new ObjectMapper(); likeInfo = mapper.readValue(jsonContent, Like.class); } catch (Exception ex) { ex.printStackTrace(); } return likeInfo; }
From source file:com.shampan.db.collections.fragment.common.Share.java
public static Share getStatusShare(String jsonContent) { Share shareInfo = null;/* www . ja v a 2 s . c o m*/ try { ObjectMapper mapper = new ObjectMapper(); shareInfo = mapper.readValue(jsonContent, Share.class); } catch (Exception ex) { ex.printStackTrace(); } return shareInfo; }
From source file:com.sitewhere.hbase.common.MarshalUtils.java
/** * Unmarshal a JSON string to an object. * /*from ww w. j av a 2 s . c o m*/ * @param json * @param type * @return * @throws SiteWhereException */ public static <T> T unmarshalJson(byte[] json, Class<T> type) throws SiteWhereException { ObjectMapper mapper = new ObjectMapper(); try { return mapper.readValue(json, type); } catch (Throwable e) { throw new SiteWhereException("Unable to parse JSON.", e); } }