Example usage for com.fasterxml.jackson.databind JsonNode toString

List of usage examples for com.fasterxml.jackson.databind JsonNode toString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode toString.

Prototype

public abstract String toString();

Source Link

Usage

From source file:au.org.ands.vocabs.toolkit.db.TestJsonParsing.java

/** Main program.
 * @param args Command-line arguments.//from www.j a  v  a2s  .c o  m
 */
public static void main(final String[] args) {
    String jsonString = "[{\"type\": \"HARVEST\",\"provider_type\":" + " \"PoolParty\",\"project_id\":"
            + " \"1DCE1494-A022-0001-FFBD-12DE19E01FEB\"},"
            + "{\"type\": \"TRANSFORM\"},{\"type\": \"IMPORT\"}]";
    JsonNode root = TaskUtils.jsonStringToTree(jsonString);
    if (root == null) {
        System.out.println("Got null.");
    } else {
        System.out.println("Got instance of:" + root.getClass().toString());
        if (!(root instanceof ArrayNode)) {
            System.out.println("Didn't get an array.");
        } else {
            for (JsonNode node : (ArrayNode) root) {
                System.out.println("Got element: " + node.toString());
                if (!(node instanceof ObjectNode)) {
                    System.out.println("Didn't get an object.");
                } else {
                    System.out.println("task type: " + node.get("type"));
                }
            }
        }
    }
}

From source file:edu.usd.btl.ontology.ToolTree.java

public static void main(String[] args) throws Exception {
    try {/*from  w  ww.  j a va 2  s.com*/
        //File ontoInput = new File(".\\ontology_files\\EDAM_1.3.owl");
        ObjectMapper mapper = new ObjectMapper();
        OntologyFileRead ontFileRead = new OntologyFileRead();
        ArrayList<edu.usd.btl.ontology.BioPortalElement> nodeList = ontFileRead
                .readFile(".\\ontology_files\\EDAM_1.3.owl");
        //write nodelist to JSON string
        ObjectWriter treeWriter = mapper.writer().withDefaultPrettyPrinter();
        String edamJSON = mapper.writeValueAsString(nodeList);

        JsonNode rootNode = mapper.readValue(edamJSON, JsonNode.class);
        System.out.println("IsNull" + rootNode.toString());

        OntSearch ontSearch = new OntSearch();
        System.out.println(nodeList.get(0).getURI());
        String result = ontSearch.searchElementByURI("http://edamontology.org/topic_2817");
        System.out.println("RESULT = " + result);

        String topicSearchResult = ontSearch.findAllTopics();
        System.out.println("Topics Result = " + topicSearchResult);

        File ontFile = new File(".\\ontology_files\\EDAM_1.3.owl");
        String searchFromFileResult = ontSearch.searchNodeFromFile("http://edamontology.org/topic_2817",
                ".\\ontology_files\\EDAM_1.3.owl");
        System.out.println("File Response = " + searchFromFileResult.toString());
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }

    //Hashmap stuff
    //        OntologyFileRead ontFileRead = new OntologyFileRead();
    //        ArrayList<edu.usd.btl.ontology.BioPortalElement> nodeList = ontFileRead.readFile(".\\ontology_files\\EDAM_1.3.owl");
    //        
    //        HashMap hm = new HashMap();
    //        
    //        //find topics
    //        ArrayList<OntologyNode> ontoTopicList = new ArrayList();
    //        
    //        for(BioPortalElement node : nodeList){
    //            //System.out.println("****" + node.getURI());
    //            hm.put(node.getURI(), node.getName());
    //        }
    //        
    //        Set set = hm.entrySet();
    //        Iterator i = set.iterator();
    //        while(i.hasNext()){
    //            Map.Entry me = (Map.Entry)i.next();
    //            System.out.println(me.getKey() + ": " + me.getValue());
    //        }
    //        System.out.println("HashMap Size = " + hm.size());
}

From source file:com.ibm.watson.catalyst.corpus.tfidf.SearchTemplate.java

public static void main(String[] args) {

    System.out.println("Loading Corpus.");
    TermCorpusBuilder cb = new TermCorpusBuilder();
    cb.setDocumentCombiner(0, 0);/* www.  j a v a2  s  . com*/
    cb.setJson(new File("health-corpus.json"));
    TermCorpus c = cb.build();

    List<TermDocument> termDocuments = c.getDocuments();
    List<TemplateMatch> matches = new ArrayList<TemplateMatch>();

    Pattern p3 = Template.getTemplatePattern(new File("verbs-list.words"), "\\b(\\w+ )", "( \\w+)\\b");

    int index = 0;
    for (TermDocument termDocument : termDocuments) {
        DocumentMatcher dm = new DocumentMatcher(termDocument);

        matches.addAll(dm.getParagraphMatches(p3, "", ""));

        double progress = ((double) ++index / (double) termDocuments.size());
        System.out.print("Progress " + progress + "\r");
    }
    System.out.println();

    WordFrequencyHashtable f = new WordFrequencyHashtable();

    for (TemplateMatch match : matches) {
        f.put(match.getMatch(), 1);
    }

    JsonNode jn = f.toJsonNode(5);

    try (BufferedWriter bw = new BufferedWriter(new FileWriter("health-trigrams.json"))) {
        bw.write(jn.toString());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.ning.metrics.collector.util.LocalFileReader.java

public static void main(String[] args) throws IOException {
    InputStream stream = null;//from  w  w w  .ja  v a  2 s .  c  om
    try {
        stream = new BufferedInputStream(new FileInputStream(args[0]));
        final SmileEnvelopeEventDeserializer deserializer = new SmileEnvelopeEventDeserializer(stream, false);
        while (deserializer.hasNextEvent()) {
            final SmileEnvelopeEvent event = deserializer.getNextEvent();
            final JsonNode node = (JsonNode) event.getData();

            final Iterator<JsonNode> elements = node.elements();
            boolean first = true;
            while (elements.hasNext()) {
                final JsonNode jsonNode = elements.next();
                if (!first) {
                    System.out.print(",");
                }
                System.out.print(jsonNode.toString());
                first = false;
            }
            System.out.print("\n");
        }
    } finally {
        if (stream != null) {
            stream.close();
        }
        System.out.flush();
    }
}

From source file:software.uncharted.util.HTTPUtil.java

public static String post(String url, JsonNode body) {
    return post(url, body.toString());
}

From source file:com.ecomnext.rest.utils.Json.java

/**
 * Convert a JsonNode to its json string representation.
 *///from   w  w w . ja  v a2s  .  c o  m
public static String stringify(JsonNode json) {
    return json.toString();
}

From source file:org.ocsoft.olivia.core.OliviaFinalizer.java

private static void storeState(String key, JsonStorable store) {
    try {//from  w  ww .j  a  va 2  s . c  om
        JsonNode json = store.storeStateAsJson();
        Olivia.getConfig().getUser().setJson(key, json.toString());
    } catch (IOException e) {
        OliviaLogger.catchException(e);
    }
}

From source file:com.github.fge.jsonschema.process.Index.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public static Response validate(@FormParam("input") final String schema,
        @FormParam("input2") final String data) {
    if (schema == null || data == null)
        return BAD;
    try {/*from w  w w  . j a  v  a2 s  .c  o m*/
        final JsonNode ret = buildResult(schema, data);
        return Response.ok().entity(ret.toString()).build();
    } catch (IOException e) {
        log.error("I/O error while validating data", e);
        return OOPS;
    }
}

From source file:com.flipkart.zjsonpatch.JsonPatch.java

private static List<String> getPath(JsonNode path) {
    List<String> paths = Splitter.on('/').splitToList(path.toString().replaceAll("\"", ""));
    return Lists.newArrayList(Iterables.transform(paths, DECODE_PATH_FUNCTION));
}

From source file:com.github.tomakehurst.wiremock.matching.EqualToJsonPattern.java

public static JsonNode getNodeAtPath(JsonNode rootNode, JsonNode path) {
    String pathString = path.toString().equals("\"/\"") ? "\"\"" : path.toString();
    return getNode(rootNode, getPath(pathString), 1);
}