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.timeinc.seleniumite.environment.EnvironmentUtils.java
public static RawGlobalTestConfiguration parseGlobalTestConfigurationFile(InputStream ios) { try {/*from w w w .j a va 2 s. co m*/ ObjectMapper om = new ObjectMapper(); return om.readValue(ios, RawGlobalTestConfiguration.class); } catch (IOException ioe) { throw new RuntimeException("Couldn't process global test configuration", ioe); } }
From source file:aot.util.IOUtil.java
public static <T> T deserialize(ObjectMapper mapper, String content, Class<T> clazz) { try {/* w w w. ja v a2 s . c o m*/ return mapper.readValue(content, clazz); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.krj.karbon.GetOwnedGames.java
public static List<Game> retrieve(String steamId) { String urlString = ""; List<Game> games = new ArrayList(); try {/*from w w w. j a va 2 s . co m*/ String host = "http://api.steampowered.com/"; String path = "IPlayerService/GetOwnedGames/v0001/"; String key = "?key=06326BE3F53F72F8C6EF31C158FBACD7"; String id = "&steamid=" + steamId; String include = "&include_appinfo=1"; String format = "&format=json"; urlString = host + path + key + id + include + format; URL url = new URL(urlString); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> JSONMap = mapper.readValue(url, Map.class); Map response = (Map) JSONMap.get("response"); List<Map> gameMaps = (List<Map>) response.get("games"); if (gameMaps != null) { for (Map map : gameMaps) { Game game = new Game(); int appid = (int) map.get("appid"); game.setAppid(appid); String name = (String) map.get("name"); game.setName(name); String imgURL = ((String) map.get("img_icon_url")); imgURL = "http://media.steampowered.com/steamcommunity/public/images/apps/" + game.getAppid() + imgURL + ".jpg"; game.setImg_icon_url(imgURL); imgURL = (String) map.get("img_logo_url"); imgURL = "http://media.steampowered.com/steamcommunity/public/images/apps/" + game.getAppid() + "/" + imgURL + ".jpg"; game.setImg_logo_url(imgURL); if (map.get("playtime_2weeks") != null) { int playtime_2weeks = (int) map.get("playtime_2weeks"); game.setPlaytime_2weeks(String.valueOf(playtime_2weeks)); } games.add(game); } } } catch (IOException ex) { Logger.getLogger(GetOwnedGames.class.getName()).log(Level.SEVERE, null, ex); } return games; }
From source file:com.millcreeksoftware.amliclookup.fcclookup.FccLookupHandler.java
/** * Gets the FCC data for the provided call sign. * /*from w w w .ja va 2 s.com*/ * @param callSign The call sign to lookup. * * @return A populated <code>FccLookupData</code>. */ public static FccLookupData getFccData(String callSign) { FccLookupData fccLookupData = new FccLookupData(); URL url; try { url = new URL(FCC_LOOKUP_BASE_URL + callSign); ObjectMapper m = new ObjectMapper(); JsonNode rootNode = m.readValue(url.openStream(), JsonNode.class); String status = rootNode.path("status").textValue(); if (!"OK".equalsIgnoreCase(status)) { return fccLookupData; } fccLookupData.setStatusOK(true); JsonNode licensesNode = rootNode.path("Licenses"); String lastUpdate = licensesNode.path("lastUpdate").asText(); fccLookupData.setLastUpdate(lastUpdate); JsonNode licenseNode = licensesNode.path("License"); JsonNode arrayNode = licenseNode.path(0); String frn = arrayNode.path("frn").asText(); fccLookupData.setFrn(frn); String statusDesc = arrayNode.path("statusDesc").asText(); fccLookupData.setStatusDesc(statusDesc); String expiredDate = arrayNode.path("expiredDate").asText(); fccLookupData.setExpireDate(expiredDate); String licenseId = arrayNode.path("licenseID").asText(); fccLookupData.setLicenseId(licenseId); fccLookupData.setFccUrl(FFC_MORE_INFO_BASE_URL + licenseId); } catch (MalformedURLException e) { fccLookupData.setStatusOK(false); logger.warn("Error looking up call '" + callSign + "'.", e); } catch (JsonParseException e) { fccLookupData.setStatusOK(false); logger.warn("Error looking up call '" + callSign + "'.", e); } catch (JsonMappingException e) { fccLookupData.setStatusOK(false); logger.warn("Error looking up call '" + callSign + "'.", e); } catch (IOException e) { fccLookupData.setStatusOK(false); logger.warn("Error looking up call '" + callSign + "'.", e); } return fccLookupData; }
From source file:com.netsteadfast.greenstep.util.JFreeChartDataMapperUtils.java
@SuppressWarnings("unchecked") public static Map<String, Object> getChartData2Map(String uploadOid) throws Exception { if (StringUtils.isBlank(uploadOid)) { throw new Exception(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK)); }// w w w . j a va 2s . c o m String jsonData = new String(UploadSupportUtils.getDataBytes(uploadOid)); ObjectMapper mapper = new ObjectMapper(); return (Map<String, Object>) mapper.readValue(jsonData, HashMap.class); }
From source file:com.wso2telco.core.pcrservice.util.YamlReader.java
/** * Gets the configuration./* ww w .j a v a 2 s . co m*/ * * @return the configuration */ public static ConfigDTO getConfiguration() { File file = new File(DEVICE_MGT_CONFIG_PATH); ConfigDTO configPojo = new ConfigDTO(); final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson databind try { configPojo = mapper.readValue(file, ConfigDTO.class); } catch (JsonParseException e) { log.error("Yaml Parsing Error", e); } catch (JsonMappingException e) { log.error("Yaml Mapping Error", e); } catch (IOException e) { log.error("Yaml File Error", e); } return configPojo; }
From source file:com.chiralBehaviors.slp.hive.configuration.MulticastConfiguration.java
public static MulticastConfiguration fromYaml(InputStream yaml) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); //mapper.registerModule(new EngineModule()); return mapper.readValue(yaml, MulticastConfiguration.class); }
From source file:com.chiralBehaviors.slp.hive.hardtack.configuration.PushConfiguration.java
public static PushConfiguration fromYaml(InputStream yaml) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); //mapper.registerModule(new EngineModule()); return mapper.readValue(yaml, PushConfiguration.class); }
From source file:com.elemenopy.backupcopy.config.BackupConfig.java
private static BackupConfig loadConfigFile(InputStream in) { if (in == null) return null; try {/* w w w . ja va 2 s . c om*/ ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally BackupConfig config = mapper.readValue(in, BackupConfig.class); return config; } catch (IOException ex) { logger.error("IO Exception while loading config file", ex); return null; } }
From source file:com.netflix.genie.common.util.JsonUtils.java
/** * Convert a JSON string of a collection back to a Java object. * * @param source The JSON string//from w w w. ja va 2 s . c om * @param typeReference The type reference of the collection to unmarshall to * @param <T> The type of the collection ie Set of String * @return The Java object * @throws GenieException For any exception during unmarshalling */ public static <T extends Collection> T unmarshall(final String source, final TypeReference<T> typeReference) throws GenieException { try { final ObjectMapper mapper = new ObjectMapper(); if (StringUtils.isNotBlank(source)) { return mapper.readValue(source, typeReference); } else { return mapper.readValue("[]", typeReference); } } catch (final IOException ioe) { throw new GenieServerException(ioe); } }