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:org.caratarse.auth.client.CaratarseAuthClient0100Test.java

@Test
public void getUser() throws IOException {
    CaratarseAuthClient client = CaratarseAuthClientFactory.getClient();
    final String userUuid = "a1ab82a6-c8ce-4723-8532-777c4b05d03c";
    ApiResponse response = client.getUser(userUuid);
    assertEquals("OK", response.getCode());
    JsonNode userTree = toTree(response.getContent());
    log.debug(userTree.toString());
    assertEquals(userUuid, userTree.get("uuid").asText());
}

From source file:org.springframework.tuple.JsonStringToTupleConverter.java

private List<Object> nodeToList(JsonNode node) throws JsonProcessingException {
    List<Object> list = new ArrayList<Object>(node.size());
    for (int i = 0; i < node.size(); i++) {
        JsonNode item = node.get(i);
        if (item.isObject()) {
            list.add(convert(item.toString()));
        } else if (item.isArray()) {
            list.add(nodeToList(item));// www. j  av  a 2 s.  c  o  m
        } else if (item.isNull()) {
            list.add(null);
        } else if (item.isBoolean()) {
            list.add(item.booleanValue());
        } else if (item.isNumber()) {
            list.add(item.numberValue());
        } else {
            list.add(mapper.treeToValue(item, Object.class));
        }
    }
    return list;
}

From source file:com.github.fge.avro.Avro2JsonSchemaProcessor.java

@Override
public SchemaTree rawProcess(final ProcessingReport report, final JsonTree input) throws ProcessingException {
    final JsonNode node = input.getBaseNode();

    final Schema avroSchema;
    try {/*from   www.j  a v  a 2s.c  om*/
        final String s = node.toString();
        avroSchema = new Schema.Parser().parse(s);
    } catch (AvroRuntimeException e) {
        /*
         * There is a SchemaParseException, but it does not cover all cases.
         *
         * This schema, for instance, throws a AvroRuntimeException:
         *
         * { "type": [ "null", "null" ] }
         *
         */
        throw new IllegalAvroSchemaException(e);
    }

    final MutableTree tree = new MutableTree();
    final Schema.Type avroType = avroSchema.getType();
    AvroTranslators.getTranslator(avroType).translate(avroSchema, tree, report);

    return new CanonicalSchemaTree(tree.getBaseNode());
}

From source file:org.caratarse.auth.client.CaratarseAuthClient0100Test.java

@Test
public void getUserByUsername() throws IOException {
    CaratarseAuthClient client = CaratarseAuthClientFactory.getClient();
    final String username = "lucio";
    ApiResponse response = client.getUserByUsername(username);
    assertEquals("OK", response.getCode());
    JsonNode rootTree = toTree(response.getContent());
    log.debug(rootTree.toString());
    JsonNode userTree = rootTree.get("_embedded").get("users").get(0);
    assertEquals(username, userTree.get("username").asText());
}

From source file:com.kenlin.awsec2offering.Offering.java

@Override
public String toString() {
    try {//from   w  w w  .  ja  v a 2  s. c om
        JsonNode json = toJsonNode();
        return json.toString();
    } catch (JsonProcessingException e1) {
        e1.printStackTrace();
        return null;
    } catch (IOException e1) {
        e1.printStackTrace();
        return null;
    }
}

From source file:com.flipkart.poseidon.api.APILoader.java

private void loadBuildables(String config) throws Exception {
    JsonNode nodes = getMapper().readTree(config);

    if (!nodes.isArray()) {
        throw new Exception("Config is not an array of buildables");
    }//  www . jav  a 2  s  .c o  m

    for (JsonNode node : nodes) {
        try {
            pojos.add(getMapper().readValue(node.toString(), EndpointPOJO.class));
        } catch (Exception exception) {
            logger.error("Error in de-serializing a config: " + node.toString(), exception);
        }
    }
}

From source file:edu.usd.btl.toolTree.OntoToTree.java

public String jsonToJava(String input) throws Exception {
    try {//  w  w  w .j  a v a 2s.c  o m
        //File input = new File("C:\\Users\\Tyler\\Documents\\GitHub\\BTL\\src\\ontology_files\\testEdam.json");

        /*
         CONVERT JSON TO JAVA OBJECTS
         */
        //map EDAM ontology JSON to List of objects
        ObjectMapper treeMapper = new ObjectMapper(); //create new Jackson Mapper
        ObjectWriter treeWriter = treeMapper.writer().withDefaultPrettyPrinter();
        List<EDAMNode> ontologyNodes = treeMapper.readValue(input,
                treeMapper.getTypeFactory().constructCollectionType(List.class, EDAMNode.class));
        System.out.println("********SIZE OF ontologyNodes*********" + ontologyNodes.size());
        for (EDAMNode node : ontologyNodes) { //for each ontology node
            System.out.println(node.getName());
            //build tree from ontology nodes

        }
        JsonNode rootNode = treeMapper.readValue(getOntoJson(), JsonNode.class);
        JsonNode tool = rootNode.get("name");

        System.out.println("\n\n\n\n****************************" + tool.toString());
        System.out.println("**** ONTOLOGY SIZE *****" + ontologyNodes.size());
        String jsonOutput = treeWriter.writeValueAsString(ontologyNodes.get(0));
        System.out.println("\n\n****ONTOLOGY JSON OUPUT*****+\n" + jsonOutput);

        //            IplantV1 iplantOutput = BETSConverter.toIplant(betsTool);
        //            String iplantOutputJson = iplantWriter.writeValueAsString(iplantOutput); //write Json as String
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }
    return "jsonToJava success";
}

From source file:org.gravidence.gravifon.db.ViewQueryArguments.java

/**
 * Adds <code>key</code> query argument.
 * //w  w w  .j  av  a2 s  .  c o m
 * @param value query argument value
 * @return reference to this object
 */
public ViewQueryArguments addKey(JsonNode value) {
    arguments.put("key", value.toString());

    return this;
}

From source file:com.opsie.opsiecomponent.test.ComponentTest.java

@Test
public void test_parse_json() {
    String testData = null;/*from   ww w .  j  a  v  a  2s  .c o m*/
    try {
        testData = IOUtils.toString(testPageWithTestsData.getInputStream());
    } catch (IOException ex) {
        Logger.getLogger(ComponentTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.valueToTree(testData);
    System.out.println("node here = " + node.toString());
}

From source file:org.gravidence.gravifon.db.ViewQueryArguments.java

/**
 * Adds <code>endkey</code> query argument.
 * //from   w ww . j a  v a  2s .  co m
 * @param value query argument value
 * @return reference to this object
 */
public ViewQueryArguments addEndKey(JsonNode value) {
    arguments.put("endkey", value.toString());

    return this;
}