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.github.tomakehurst.wiremock.common.Json.java
public static <T> T read(String json, Class<T> clazz) { try {//w w w.j ava2 s .c o m ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); return mapper.readValue(json, clazz); } catch (IOException ioe) { throw new RuntimeException( "Unable to bind JSON to object. Reason: " + ioe.getMessage() + " JSON:" + json, ioe); } }
From source file:com.chiralBehaviors.groo.configuration.GrooConfiguration.java
public static GrooConfiguration fromYaml(InputStream yaml) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); mapper.registerModule(new DiscoveryModule()); return mapper.readValue(yaml, GrooConfiguration.class); }
From source file:com.chiralBehaviors.slp.hive.configuration.HiveScopeConfiguration.java
public static HiveScopeConfiguration fromYaml(InputStream yaml) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); mapper.registerModule(new EngineModule()); return mapper.readValue(yaml, HiveScopeConfiguration.class); }
From source file:io.fabric8.kubernetes.client.internal.KubeConfigUtils.java
public static Config parseConfig(File file) throws IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); return mapper.readValue(file, Config.class); }
From source file:com.boundary.sdk.snmp.metric.OidMapList.java
public static OidMapList load(String resource) throws URISyntaxException { OidMapList instance = new OidMapList(); ClassLoader classLoader = instance.getClass().getClassLoader(); URL url = classLoader.getResource(resource); File file = new File(url.toURI()); ObjectMapper mapper = new ObjectMapper(); try {/*from ww w . j a v a 2 s . c o m*/ instance = mapper.readValue(file, OidMapList.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return instance; }
From source file:io.fouad.jtb.core.utils.JsonUtils.java
public static <T> T toJavaObject(String json, Class<T> clazz) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); return mapper.readValue(json, clazz); }
From source file:io.fouad.jtb.core.utils.JsonUtils.java
public static <T, R> T toJavaObject(String json, TypeReference typeReference) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); return mapper.readValue(json, typeReference); }
From source file:com.jaeksoft.opensearchserver.ServerConfiguration.java
/** * Load the configuration file.//from w w w .j a va 2 s . c o m * * @param file * @return an instance of ServerConfiguration * @throws JsonParseException * @throws JsonMappingException * @throws IOException */ static ServerConfiguration getNewInstance(File file) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); return mapper.readValue(file, ServerConfiguration.class); }
From source file:Main.java
public static <T> T convertObjectFromMap(Map<String, Object> map, String key, Class<T> tClass) { if (map == null) return null; Object obj = map.get(key);/*from www. j a v a 2 s . c o m*/ String json = null; if (obj != null) json = serilizeJavaObject(obj); else return null; ObjectMapper mapper = new ObjectMapper(); T returnVal = null; try { returnVal = (T) mapper.readValue(json, tClass); } catch (JsonParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return returnVal; }
From source file:com.boundary.sdk.snmp.metric.HostLists.java
public static HostLists load(String resource) throws URISyntaxException { HostLists instance = new HostLists(); ClassLoader classLoader = instance.getClass().getClassLoader(); URL url = classLoader.getResource(resource); File file = new File(url.toURI()); ObjectMapper mapper = new ObjectMapper(); try {/*from w w w . ja v a2 s . c o m*/ instance = mapper.readValue(file, HostLists.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return instance; }