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.amazon.android.navigator.NavigatorModelParser.java
/** * Parses the Navigator JSON file into a {@link NavigatorModel} object. The JSON file is * defined/*from w w w . ja va 2 s .co m*/ * by the {@link Navigator#NAVIGATOR_FILE} string. * * @param context The context. * @return A NavigatorModel object. */ public static NavigatorModel parse(Context context, String navigatorFile) { NavigatorModel navigatorModel = null; try { ObjectMapper objectMapper = new ObjectMapper(); String navigatorFileString = FileHelper.readFile(context, navigatorFile); navigatorModel = objectMapper.readValue(navigatorFileString, NavigatorModel.class); Log.v(TAG, "Navigator Model: " + navigatorModel.toString()); // Preload recipes for (NavigatorModel.GlobalRecipes globalRecipes : navigatorModel.getGlobalRecipes()) { // Load category recipes if there is no hard coded name defined. if (globalRecipes.getCategories() != null && globalRecipes.getCategories().name == null) { globalRecipes.getCategories().dataLoaderRecipe = Recipe.newInstance(context, globalRecipes.getCategories().dataLoader); globalRecipes.getCategories().dynamicParserRecipe = Recipe.newInstance(context, globalRecipes.getCategories().dynamicParser); } if (globalRecipes.getContents() != null) { globalRecipes.getContents().dataLoaderRecipe = Recipe.newInstance(context, globalRecipes.getContents().dataLoader); globalRecipes.getContents().dynamicParserRecipe = Recipe.newInstance(context, globalRecipes.getContents().dynamicParser); } } // Preload Recommendation recipes if (navigatorModel.getRecommendationRecipes() != null) { for (NavigatorModel.RecommendationRecipes recommendationRecipes : navigatorModel .getRecommendationRecipes()) { if (recommendationRecipes.getContents() != null) { recommendationRecipes.getContents().dataLoaderRecipe = Recipe.newInstance(context, recommendationRecipes.getContents().dataLoader); recommendationRecipes.getContents().dynamicParserRecipe = Recipe.newInstance(context, recommendationRecipes.getContents().dynamicParser); } } } } catch (Exception e) { Log.e(TAG, "Navigator parsing failed!!! ", e); } return navigatorModel; }
From source file:com.ibm.iotf.connector.Connector.java
public static <T> T parseEnv(String serviceName, Class<T> classType) { try {//from w w w . j av a 2 s. c o m String vcap = System.getenv("VCAP_SERVICES"); if (vcap == null) { logger.log(Level.FATAL, "VCAP_SERVICES env var not defined"); return null; } ObjectMapper mapper = new ObjectMapper(); JsonNode vcapServicesJson = mapper.readValue(vcap, JsonNode.class); // only attempt to parse the config if the env has an entry for the requested service if (vcapServicesJson.has(serviceName)) { T env = mapper.readValue(vcapServicesJson.get(serviceName).get(0).toString(), classType); return env; } else { logger.log(Level.FATAL, "Error parsing VCAP_SERVICES: Could not find a service instance for '" + serviceName + "'."); } } catch (Exception e) { logger.log(Level.FATAL, "Error parsing service configuraton from VCAP_SERVICES for service '" + serviceName + "': " + e.getMessage(), e); } return null; }
From source file:fi.luontola.cqrshotel.JsonSerializationTest.java
private static void assertSerializable(Class<?> type, ObjectMapper objectMapper) { try {/* ww w. j av a 2 s. c o m*/ Object original = newDummy(type); String json = objectMapper.writeValueAsString(original); Object deserialized = objectMapper.readValue(json, type); assertThat(deserialized, is(original)); } catch (Exception e) { throw new AssertionError("Not serializable: " + type, e); } }
From source file:com.twosigma.beaker.table.serializer.TableDisplayDeSerializer.java
@SuppressWarnings("unchecked") public static List<String> getColumns(JsonNode n, ObjectMapper mapper) throws IOException { List<String> columns = null; if (n.has("columnNames")) columns = mapper.readValue(n.get("columnNames").asText(), List.class); return columns; }
From source file:com.netflix.suro.routing.TestMessageRouter.java
private static Map<String, Sink> getSinkMap(ObjectMapper jsonMapper, String desc) throws Exception { return jsonMapper.readValue(desc, new TypeReference<Map<String, Sink>>() { });/* ww w . j a va 2 s . c om*/ }
From source file:com.netflix.suro.routing.TestMessageRouter.java
private static Map<String, RoutingInfo> getRoutingMap(ObjectMapper jsonMapper, String desc) throws Exception { return jsonMapper.readValue(desc, new TypeReference<Map<String, RoutingInfo>>() { });//from www .ja v a 2 s .c om }
From source file:com.streamsets.datacollector.util.PipelineConfigurationUtil.java
private static PipelineConfiguration getPipelineConfiguration(String pipelineJson) throws IOException { ObjectMapper json = ObjectMapperFactory.getOneLine(); PipelineConfigurationJson pipelineConfigBean = json.readValue(pipelineJson, PipelineConfigurationJson.class); return BeanHelper.unwrapPipelineConfiguration(pipelineConfigBean); }
From source file:at.becast.youploader.account.Account.java
public static Account read(String name) throws IOException { PreparedStatement stmt;/*from w ww . ja v a2s . co m*/ try { stmt = c.prepareStatement("SELECT * FROM `accounts` WHERE `name`=? LIMIT 1"); stmt.setString(1, name); ResultSet rs = stmt.executeQuery(); ObjectMapper mapper = new ObjectMapper(); List<Cookie> c = mapper.readValue(rs.getString("cookie"), new TypeReference<List<Cookie>>() { }); int id = rs.getInt("id"); String token = rs.getString("refresh_token"); stmt.close(); rs.close(); return new Account(id, name, token, c); } catch (SQLException e) { LOG.error("Account read error!", e); return null; } }
From source file:at.becast.youploader.account.Account.java
public static Account read(int id) throws IOException { PreparedStatement stmt;/*w w w .ja va 2 s . co m*/ try { stmt = c.prepareStatement("SELECT * FROM `accounts` WHERE `id`=? LIMIT 1"); stmt.setInt(1, id); ResultSet rs = stmt.executeQuery(); ObjectMapper mapper = new ObjectMapper(); List<Cookie> c = mapper.readValue(rs.getString("cookie"), new TypeReference<List<Cookie>>() { }); String name = rs.getString("name"); String token = rs.getString("refresh_token"); stmt.close(); rs.close(); return new Account(id, name, token, c); } catch (SQLException e) { LOG.error("Account read error!", e); return null; } }
From source file:uk.ac.sanger.cgp.wwdocker.actions.Utils.java
public static Object jsonToObject(String json, Class classType) { ObjectMapper mapper = new ObjectMapper(); Object obj;//from www . j ava 2 s . c o m try { obj = mapper.readValue(json, classType); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } return obj; }