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:ch.netzwerg.paleo.schema.Schema.java
public static Schema parseJson(Reader in) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.readValue(in, Schema.class); }
From source file:de.unirostock.sems.cbarchive.web.dataholder.UserData.java
@JsonIgnore public static UserData fromJson(String json) throws JsonParseException, JsonMappingException, IOException { if (json == null) return null; json = new String(Base64.decodeBase64(json)); ObjectMapper mapper = new ObjectMapper(); UserData result = mapper.readValue(json, UserData.class); return result; }
From source file:com.boundary.sdk.event.notification.AlarmNotification.java
public static AlarmNotification load(String resource) throws URISyntaxException { AlarmNotification instance = new AlarmNotification(); 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. jav a 2s .c om*/ instance = mapper.readValue(file, AlarmNotification.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return instance; }
From source file:com.boundary.plugin.sdk.jmx.JMXPluginConfiguration.java
public static JMXPluginConfiguration getConfiguration() { ObjectMapper mapper = new ObjectMapper(); JMXPluginConfiguration configuration = null; try {//ww w.j a va 2 s . c om configuration = mapper.readValue(new File(PLUGIN_PARAMETER_FILENAME), JMXPluginConfiguration.class); } 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 configuration; }
From source file:de.oth.keycloak.initKeycloakServer.IT_TestAuth.java
@BeforeClass public static void setUpClass() throws IOException { keycloak = initKeycloak(SERVER, REALM, USER, PWD, CLIENTSTR); String initFileStr = "integration_test_config.json"; File initFile = new File(initFileStr); if (!initFile.isFile()) { URL url = TestRun.class.getClassLoader().getResource(initFileStr); if (url != null) { initFile = new File(url.getFile()); if (!initFile.isFile()) { fail("test config is no file: " + initFileStr); }/*from w w w . j av a2s.c o m*/ } else { fail("can't load test config: " + initFileStr); } } RealmResource rRes = KeycloakAccess.getRealm(keycloak, GM_REALM, false); if (rRes != null) { rRes.remove(); } rRes = KeycloakAccess.getRealm(keycloak, APP_REALM, false); if (rRes != null) { rRes.remove(); } ObjectMapper mapper = new ObjectMapper(); RealmsConfig realmsConfig = mapper.readValue(initFile, RealmsConfig.class); if (realmsConfig != null) { List<RealmConfig> realmList = realmsConfig.getRealms(); if (realmList == null || realmList.isEmpty()) { fail("realmList is empty: " + initFileStr); } for (RealmConfig realmConf : realmList) { InitKeycloakServer.addRealm(keycloak, realmConf); } } else { fail("no realm config found in: " + initFileStr); } }
From source file:org.smartdeveloperhub.vocabulary.config.ConfigurationFactory.java
static <T extends Configuration> T load(final URL url, final Class<? extends T> clazz) throws IOException { final ObjectMapper mapper = parsingMapper(); try (InputStream openStream = url.openStream()) { return mapper.readValue(openStream, clazz); }/* w w w .j a va2 s . c o m*/ }
From source file:com.exalttech.trex.stateful.models.trexlatencyv2.FilterTrexLatencyV2ResponseUtil.java
/** * Filter Response to create PortProperty * * @return// w w w.ja v a2 s . c o m */ public static List<PortProperty> filterPortPropertiesArray(String response) { JSONObject jObject = new JSONObject(response); JSONObject data = jObject.getJSONObject("data"); int numOfPorts = countNumberOfPorts(response); List<PortProperty> portProperty = new ArrayList<PortProperty>(); ObjectMapper mapper = new ObjectMapper(); for (int i = 0; i < numOfPorts; i++) { try { portProperty.add(mapper.readValue(data.getJSONObject("port-" + i).toString(), PortProperty.class)); } catch (Exception ex) { LOG.error("Error: ", ex); } } return portProperty; }
From source file:am.ik.sendgrid.util.JsonCodec.java
public static <T> Function<InputStream, T> decode(ObjectMapper objectMapper, Class<T> type) { return inputStream -> { try (InputStream in = inputStream) { return objectMapper.readValue(in, type); } catch (IOException e) { throw new UncheckedIOException("Unable to parse JSON Payload", e); }/* w w w . j a va 2 s. co m*/ }; }
From source file:es.logongas.iothome.agent.ConfigLoader.java
public static Config getConfig(String fileName) { Config config;//from ww w .j ava 2 s . c o m InputStream inputStream = null; try { ObjectMapper objectMapper = new ObjectMapper(); inputStream = new BufferedInputStream(new FileInputStream(fileName)); config = (Config) objectMapper.readValue(inputStream, Config.class); return config; } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException ex) { Logger.getLogger(Storage.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:at.plechinger.spring.security.scribe.JsonUtil.java
public static Map<String, Object> parseMap(String input) throws IOException { JsonFactory factory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(factory); TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { };/*w ww . j ava 2 s . c o m*/ return mapper.readValue(input, typeRef); }