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:edu.usf.cutr.open311client.utils.Open311Parser.java
/** * Parses json string result for service list * * @param json string result/*from w w w . j a va 2 s.co m*/ * @return ServiceListResponse object */ public static ServiceListResponse parseServices(String json) { if (json == null) { return new ServiceListResponse(); } ObjectMapper om = createObjectMapper(); ArrayList<Service> services; ServiceListResponse slr = new ServiceListResponse(); try { services = om.readValue(json, new TypeReference<ArrayList<Service>>() { }); slr.setServiceList(services); slr.setResultCode(Open311Constants.RESULT_OK); } catch (IOException e) { logger.error(e); } return slr; }
From source file:oracle.custom.ui.oauth.vo.OpenIdConfiguration.java
public static OpenIdConfiguration getButDontSave(String baseUrl) throws Exception { String url = baseUrl + endpoint; System.out.println("URL is '" + url + "'"); HttpClient client = ServerUtils.getClient(); URI uri = new URI(url); HttpGet get = new HttpGet(uri); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); HttpResponse response = client.execute(host, get); try {//from ww w . j a v a 2s .co m HttpEntity entity2 = response.getEntity(); String res = EntityUtils.toString(entity2); EntityUtils.consume(entity2); ObjectMapper mapper = new ObjectMapper(); //res = res.replaceAll("secureoracle.idcs.internal.oracle.com:443", "oc-140-86-12-131.compute.oraclecloud.com"); OpenIdConfiguration openIdConfigInstance = mapper.readValue(res, OpenIdConfiguration.class); return openIdConfigInstance; } finally { if (response instanceof CloseableHttpResponse) { ((CloseableHttpResponse) response).close(); } } }
From source file:oracle.custom.ui.oauth.vo.OpenIdConfiguration.java
public static OpenIdConfiguration getInstance(String tenantName) throws Exception { if (configMap.containsKey(tenantName.toLowerCase())) { return configMap.get(tenantName.toLowerCase()); }/*from w ww. ja v a2 s . c o m*/ String url = ServerUtils.getIDCSBaseURL(tenantName) + endpoint; System.out.println("URL for tenant '" + tenantName + "' is '" + url + "'"); HttpClient client = ServerUtils.getClient(tenantName); URI uri = new URI(url); HttpGet get = new HttpGet(uri); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); HttpResponse response = client.execute(host, get); try { HttpEntity entity2 = response.getEntity(); String res = EntityUtils.toString(entity2); EntityUtils.consume(entity2); ObjectMapper mapper = new ObjectMapper(); //res = res.replaceAll("secureoracle.idcs.internal.oracle.com:443", "oc-140-86-12-131.compute.oraclecloud.com"); OpenIdConfiguration openIdConfigInstance = mapper.readValue(res, OpenIdConfiguration.class); configMap.put(tenantName.toLowerCase(), openIdConfigInstance); return openIdConfigInstance; } finally { if (response instanceof CloseableHttpResponse) { ((CloseableHttpResponse) response).close(); } } }
From source file:com.twosigma.beaker.table.serializer.TableDisplayDeSerializer.java
@SuppressWarnings("unchecked") public static List<List<?>> getValues(BeakerObjectConverter parent, JsonNode n, ObjectMapper mapper) throws IOException { List<List<?>> values = null; List<String> classes = null; if (n.has("types")) classes = mapper.readValue(n.get("types").asText(), List.class); if (n.has("values")) { JsonNode nn = n.get("values"); values = new ArrayList<List<?>>(); if (nn.isArray()) { for (JsonNode nno : nn) { if (nno.isArray()) { ArrayList<Object> val = new ArrayList<Object>(); for (int i = 0; i < nno.size(); i++) { JsonNode nnoo = nno.get(i); Object obj = parent.deserialize(nnoo, mapper); val.add(TableDisplayDeSerializer.getValueForDeserializer(obj, classes != null && classes.size() > i ? classes.get(i) : null)); }/* ww w . j a v a2 s . c o m*/ values.add(val); } } } } return values; }
From source file:org.omg.bpmn.miwg.configuration.BpmnCompareConfiguration.java
public static BpmnCompareConfiguration loadConfiguration(String confName) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); if (confName == null) { confName = "conf.json"; }/* www. j av a 2s . com*/ InputStream is = BpmnCompareConfiguration.class.getResourceAsStream(confName); BpmnCompareConfiguration conf = mapper.readValue(is, BpmnCompareConfiguration.class); return conf; }
From source file:io.cslinmiso.line.utils.Utility.java
public static <T> T json2Bean(String jsonStr, Class<T> objClass) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(jsonStr, objClass); }
From source file:cn.org.once.cstack.cli.rest.JsonConverter.java
public static User getUser(String response) { User user = new User(); ObjectMapper mapper = new ObjectMapper(); try {//w w w . j a va 2s . co m user = mapper.readValue(response, User.class); } catch (IOException e) { e.printStackTrace(); } return user; }
From source file:com.mapr.synth.samplers.FieldSampler.java
public static FieldSampler newSampler(String def) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); return mapper.readValue(def, new TypeReference<FieldSampler>() { });//from ww w.j ava2s. co m }
From source file:de.javagl.jgltf.browser.MenuNodes.java
/** * Read the list of {@link MenuNode} objects from the JSON that is * provided by the given input stream. The caller is responsible * for closing the given stream.//w ww. java 2 s . co m * * @param inputStream The input stream * @return The list of {@link MenuNode} instances * @throws IOException If an IO error occurs */ private static List<? extends MenuNode> read(InputStream inputStream) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); TypeReference<List<MenuNode>> typeReference = new TypeReference<List<MenuNode>>() { // Empty class }; List<? extends MenuNode> menuNodes = objectMapper.readValue(inputStream, typeReference); return menuNodes; }
From source file:edu.usf.cutr.open311client.utils.Open311Parser.java
/** * Parses json string to Service Info Response * * @param json/* ww w.j a v a 2 s . c o m*/ * @return */ public static ServiceInfoResponse parseServiceInfos(String json) { if (json == null) { return new ServiceInfoResponse(); } ObjectMapper om = createObjectMapper(); ArrayList<ServiceInfo> serviceInfos; ServiceInfoResponse sir = new ServiceInfoResponse(); try { serviceInfos = om.readValue(json, new TypeReference<ArrayList<ServiceInfo>>() { }); sir.setServiceInfoList(serviceInfos); sir.setResultCode(Open311Constants.RESULT_OK); } catch (IOException e) { logger.error(e); } return sir; }