List of usage examples for com.fasterxml.jackson.databind ObjectMapper readTree
public JsonNode readTree(URL source) throws IOException, JsonProcessingException
From source file:acromusashi.stream.example.ml.client.LofDrpcClient.java
/** * LOF??DRPC???LOF??/*from ww w . j a v a2 s . co m*/ * * @param drpcHost DRPC * @param drpcPort DRPC? * @param drpcFunction ???? * @param lofData LOF * @return LOF * @throws DRPCExecutionException DRPC * @throws TException DRPC * @throws IOException ? */ public double sendRequest(String drpcHost, int drpcPort, String drpcFunction, String lofData) throws TException, DRPCExecutionException, IOException { DRPCClient client = new DRPCClient(drpcHost, drpcPort); String drpcResult = client.execute(drpcFunction, lofData); // ????????? // [["84.406 129.347 50.527","LofPoint[dataId=7b6f1200-7117-4231-bc95-32c448237f5b, // dataPoint={84.406,129.347,50.527},kDistance=0.0,kDistanceNeighbor=<null>,lrd=0.0,judgeDate=Tue Nov 26 18:56:00 JST 2013]", // "{\"lofScore\":1.924027244063857,\"lofPoint\":{\"dataId\":\"7b6f1200-7117-4231-bc95-32c448237f5b\", // \"dataPoint\":[84.406,129.347,50.527],\"kDistance\":0.0,\"kDistanceNeighbor\":null,\"lrd\":0.0,\"judgeDate\":1385459760464}}"]] ObjectMapper mapper = new ObjectMapper(); JsonNode baseNode = mapper.readTree(drpcResult); String lofResultStr = baseNode.get(0).get(2).asText(); JsonNode lofResultTree = mapper.readTree(lofResultStr); double lofScore = lofResultTree.get("lofScore").asDouble(); return lofScore; }
From source file:com.monarchapis.driver.configuration.JsonConfiguration.java
@Override public void load(byte[] content) throws IOException { ObjectMapper mapper = getObjectMapper(); root = mapper.readTree(content); }
From source file:com.monarchapis.driver.configuration.JsonConfiguration.java
@Override public void load(File file) throws IOException { ObjectMapper mapper = getObjectMapper(); root = mapper.readTree(file); }
From source file:com.monarchapis.driver.configuration.JsonConfiguration.java
@Override public void load(InputStream is) throws IOException { ObjectMapper mapper = getObjectMapper(); root = mapper.readTree(is); }
From source file:com.monarchapis.driver.configuration.JsonConfiguration.java
@Override public void load(Reader reader) throws IOException { ObjectMapper mapper = getObjectMapper(); root = mapper.readTree(reader); }
From source file:com.monarchapis.driver.configuration.JsonConfiguration.java
@Override public void load(String content) throws IOException { ObjectMapper mapper = getObjectMapper(); root = mapper.readTree(content); }
From source file:com.monarchapis.driver.configuration.JsonConfiguration.java
@Override public void load(URL source) throws IOException { ObjectMapper mapper = getObjectMapper(); root = mapper.readTree(source); }
From source file:org.zalando.stups.swagger.codegen.YamlToJson.java
protected String getYamlFileContentAsJson() throws IOException { String data = ""; if (yamlInputPath.startsWith("http") || yamlInputPath.startsWith("https")) { data = new String(Resources.toByteArray(new URL(yamlInputPath))); } else {/*w ww. j a v a 2s .co m*/ data = new String(Files.readAllBytes(java.nio.file.Paths.get(new File(yamlInputPath).toURI()))); } ObjectMapper yamlMapper = Yaml.mapper(); JsonNode rootNode = yamlMapper.readTree(data); // must have swagger node set JsonNode swaggerNode = rootNode.get("swagger"); return rootNode.toString(); }
From source file:com.mapr.data.sputnik.log.Log4JLogger.java
public void testme(String event) { ObjectMapper mapper = new ObjectMapper(); try {/*from ww w.ja v a 2 s . c o m*/ JsonNode node = mapper.readTree(event); Iterator<String> fieldNames = node.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); JsonNode fieldValue = node.get(fieldName); byte[] x = Bytes.toBytes(fieldName); byte[] y = Bytes.toBytes(fieldValue.toString()); } } catch (Exception e) { e.printStackTrace(); } // printAll("root", node); // System.out.print("\n"); }
From source file:org.fcrepo.camel.reindexing.RestProcessor.java
/** * Convert the incoming REST request into the correct * Fcrepo header fields.// w w w .j av a2 s. c o m * * @param exchange the current message exchange */ public void process(final Exchange exchange) throws Exception { final Message in = exchange.getIn(); final String path = in.getHeader(Exchange.HTTP_PATH, "", String.class); final String contentType = in.getHeader(Exchange.CONTENT_TYPE, "", String.class); final String body = in.getBody(String.class); final Set<String> endpoints = new HashSet<>(); for (final String s : in.getHeader(ReindexingHeaders.RECIPIENTS, "", String.class).split(",")) { endpoints.add(s.trim()); } in.removeHeaders("CamelHttp*"); in.removeHeader("JMSCorrelationID"); in.setBody(null); if (contentType.equals("application/json") && body != null && !body.trim().isEmpty()) { final ObjectMapper mapper = new ObjectMapper(); try { final JsonNode root = mapper.readTree(body); final Iterator<JsonNode> ite = root.elements(); while (ite.hasNext()) { final JsonNode n = ite.next(); endpoints.add(n.asText()); } } catch (JsonProcessingException e) { LOGGER.debug("Invalid JSON", e); in.setHeader(Exchange.HTTP_RESPONSE_CODE, BAD_REQUEST); in.setBody("Invalid JSON"); } } in.setHeader(FcrepoHeaders.FCREPO_IDENTIFIER, path); in.setHeader(ReindexingHeaders.RECIPIENTS, String.join(",", endpoints)); }