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:jvmoptions.OptionAnalyzer.java
static Map<String, Map<String, String>> readJson(Path json) throws IOException { ObjectMapper om = new ObjectMapper(); TypeReference<Map<String, Map<String, String>>> ref = new TypeReference<Map<String, Map<String, String>>>() { };//from w w w. j av a 2 s .c om Map<String, Map<String, String>> map = om.readValue(json.toFile(), ref); System.out.printf("%s contains %d options%n", json, map.keySet().size()); return map; }
From source file:cn.org.once.cstack.cli.rest.JsonConverter.java
public static List<ContainerUnit> getContainerUnits(String response) { ObjectMapper mapper = new ObjectMapper(); List<ContainerUnit> containerUnits = null; try {/* ww w.j a va 2s .co m*/ containerUnits = mapper.readValue(response, new TypeReference<List<ContainerUnit>>() { }); } catch (IOException e) { e.printStackTrace(); } return containerUnits; }
From source file:com.threecrickets.jygments.style.Style.java
@SuppressWarnings("unchecked") public static Style getByFullName(String fullName) throws ResolutionException { // Try cache/*w w w . j av a2s . c o m*/ Style style = styles.get(fullName); if (style != null) return style; try { return (Style) Jygments.class.getClassLoader().loadClass(fullName).newInstance(); } catch (InstantiationException x) { } catch (IllegalAccessException x) { } catch (ClassNotFoundException x) { } InputStream stream = Jygments.class.getClassLoader() .getResourceAsStream(fullName.replace('.', '/') + ".json"); if (stream != null) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.getFactory().configure(JsonParser.Feature.ALLOW_COMMENTS, true); try { Map<String, Object> json = objectMapper.readValue(stream, HashMap.class); style = new Style(); style.addJson(json); style.resolve(); // Cache it Style existing = styles.putIfAbsent(fullName, style); if (existing != null) style = existing; return style; } catch (JsonParseException x) { throw new ResolutionException(x); } catch (JsonMappingException x) { throw new ResolutionException(x); } catch (IOException x) { throw new ResolutionException(x); } } return null; }
From source file:com.netsteadfast.greenstep.util.SystemExpressionJobUtils.java
public static SysExprJobLogVO executeJobForManualFromRestServiceUrl(SysExprJobVO sysExprJob, String accountId, HttpServletRequest request) throws ServiceException, Exception { SysExprJobLogVO result = new SysExprJobLogVO(); // ? executeJob/ ? ManualJobServiceImpl.java @Path("/executeJob/") ?, , url ? String url = ApplicationSiteUtils.getBasePath(sysExprJob.getSystem(), request); if (!url.endsWith("/")) { url += "/"; }// w ww . java 2s . c om //url += "services/jaxrs/executeJob/"; url += Constants.getCxfWebServiceMainPathName() + Constants.getJAXRSServerFactoryBeanAddress() + "executeJob/"; String encUploadOidStr = SystemExpressionJobUtils.getEncUploadOid(accountId, sysExprJob.getOid()); url += encUploadOidStr; InputStreamReader isr = null; BufferedReader reader = null; try { HttpClient httpClient = new HttpClient(); PostMethod post = new PostMethod(url); /* NameValuePair[] data = { new NameValuePair("uploadOid", encUploadOidStr) }; post.setRequestBody(data); */ post.setParameter("uploadOid", encUploadOidStr); int statusCode = httpClient.executeMethod(post); if (statusCode != 200 && statusCode != 202) { throw new Exception("error, http status code: " + statusCode); } isr = new InputStreamReader(post.getResponseBodyAsStream()); reader = new BufferedReader(isr); String line = ""; StringBuilder str = new StringBuilder(); while ((line = reader.readLine()) != null) { str.append(line); } ObjectMapper mapper = new ObjectMapper(); result = mapper.readValue(str.toString(), SysExprJobLogVO.class); } catch (IOException e) { e.printStackTrace(); result.setFaultMsg(e.getMessage().toString()); } catch (Exception e) { e.printStackTrace(); result.setFaultMsg(e.getMessage().toString()); } finally { if (reader != null) { reader.close(); } if (isr != null) { isr.close(); } reader = null; isr = null; } return result; }
From source file:org.lambdamatic.internal.elasticsearch.clientdsl.Client.java
private static String formatJsonDocument(final String requestBody) throws IOException, JsonParseException, JsonMappingException, JsonProcessingException { final ObjectMapper mapper = new ObjectMapper(); final Object json = mapper.readValue(requestBody, Object.class); final String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json); return indented; }
From source file:org.lambdamatic.internal.elasticsearch.clientdsl.Client.java
private static String formatJsonDocument(final InputStream requestBodyStream) throws IOException, JsonParseException, JsonMappingException, JsonProcessingException { final ObjectMapper mapper = new ObjectMapper(); final Object json = mapper.readValue(requestBodyStream, Object.class); final String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json); return indented; }
From source file:io.apiman.cli.util.DeclarativeUtil.java
/** * Parses the {@link Declaration} from the {@code fileContents}, using the specified {@code properties}. * * @param mapper the Mapper to use/*from w ww. ja va 2 s. co m*/ * @param unresolved the contents of the file * @param properties the property placeholders * @return the Declaration * @throws IOException */ private static Declaration loadDeclaration(ObjectMapper mapper, String unresolved, Map<String, String> properties) throws IOException { final String resolved = BeanUtil.resolvePlaceholders(unresolved, properties); LOGGER.trace("Declaration file after resolving {} placeholders: {}", properties.size(), resolved); return mapper.readValue(resolved, Declaration.class); }
From source file:nl.esciencecenter.medim.dicom.DicomProcessingProfile.java
public static DicomProcessingProfile parseXML(String xml) throws JsonParseException, JsonMappingException, IOException { ObjectMapper xmlMapper = new XmlMapper(); DicomProcessingProfile value = xmlMapper.readValue(xml, DicomProcessingProfile.class); // check ?//w w w . j a v a2 s . c o m return value; }
From source file:com.netsteadfast.greenstep.sys.CxfServerBean.java
public static Long getBeforeValue(String paramValue) throws Exception { String value = EncryptorUtils.decrypt(Constants.getEncryptorKey1(), Constants.getEncryptorKey2(), SimpleUtils.deHex(paramValue)); byte datas[] = UploadSupportUtils.getDataBytes(value); String jsonData = new String(datas, Constants.BASE_ENCODING); ObjectMapper mapper = new ObjectMapper(); @SuppressWarnings("unchecked") Map<String, Object> dataMap = (Map<String, Object>) mapper.readValue(jsonData, HashMap.class); return NumberUtils.toLong((String) dataMap.get("before"), 0); }
From source file:de.fau.cs.inf2.tree.evaluation.Main.java
/** * Parses data/pso and prints the total number of * pso runs.//from w w w . ja va 2 s . c om */ private static void readPSODataAndPrint() { File psoDir = new File(DIR_DATA, "/pso/"); ObjectMapper mapper = TreeEvalIO.createJSONMapper(); int sum = 0; for (final File folder : psoDir.listFiles((f) -> f.isDirectory())) { for (final File psoFile : folder.listFiles((f) -> f.getName().endsWith(".json"))) { try { PsoResult result = mapper.readValue(psoFile, PsoResult.class); if (result != null) { sum++; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } System.out.println("PSO runs: " + sum); }