Example usage for com.fasterxml.jackson.databind.node JsonNodeFactory objectNode

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory objectNode

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node JsonNodeFactory objectNode.

Prototype

public ObjectNode objectNode() 

Source Link

Usage

From source file:io.debezium.data.VerifyRecord.java

protected static void printJson(SourceRecord record) {
    JsonNode keyJson = null;//w w w.  j ava  2  s .co  m
    JsonNode valueJson = null;
    try {
        // First serialize and deserialize the key ...
        byte[] keyBytes = keyJsonConverter.fromConnectData(record.topic(), record.keySchema(), record.key());
        keyJson = keyJsonDeserializer.deserialize(record.topic(), keyBytes);
        // then the value ...
        byte[] valueBytes = valueJsonConverter.fromConnectData(record.topic(), record.valueSchema(),
                record.value());
        valueJson = valueJsonDeserializer.deserialize(record.topic(), valueBytes);
        // And finally get ready to print it ...
        JsonNodeFactory nodeFactory = new JsonNodeFactory(false);
        ObjectNode message = nodeFactory.objectNode();
        message.set("key", keyJson);
        message.set("value", valueJson);
        Testing.print("Message on topic '" + record.topic() + "':");
        Testing.print(prettyJson(message));
    } catch (Throwable t) {
        Testing.printError(t);
        Testing.print("Problem with message on topic '" + record.topic() + "':");
        if (keyJson != null) {
            Testing.print("valid key = " + prettyJson(keyJson));
        } else {
            Testing.print("invalid key");
        }
        if (valueJson != null) {
            Testing.print("valid value = " + prettyJson(valueJson));
        } else {
            Testing.print("invalid value");
        }
        fail(t.getMessage());
    }
}

From source file:juzu.plugin.jackson.AbstractJacksonResponseTestCase.java

@Test
public void testResponse() throws Exception {
    HttpGet get = new HttpGet(applicationURL().toString());
    HttpClient client = HttpClientBuilder.create().build();
    HttpResponse response = client.execute(get);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertNotNull(response.getEntity());
    assertEquals("application/json;charset=ISO-8859-1", response.getEntity().getContentType().getValue());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode tree = mapper.readTree(response.getEntity().getContent());
    JsonNodeFactory factory = JsonNodeFactory.instance;
    JsonNode expected = factory.objectNode().set("foo", factory.textNode("bar"));
    assertEquals(expected, tree);/*from w  w w . j av a  2s.  com*/
}

From source file:net.mostlyharmless.jghservice.connector.github.GithubIssue.java

public JsonNode getJson() {
    JsonNodeFactory factory = JsonNodeFactory.instance;
    ObjectNode newNode = factory.objectNode();

    return null;

}

From source file:com.netflix.genie.web.controllers.RootRestController.java

/**
 * Get a simple HAL+JSON object which represents the various links available in Genie REST API as an entry point.
 *
 * @return the root resource containing various links to the real APIs
 */// w w w.  ja  v a  2s. c  om
@GetMapping(produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public RootResource getRoot() {
    final JsonNodeFactory factory = JsonNodeFactory.instance;
    final JsonNode node = factory.objectNode().set("description", factory.textNode("Genie V3 API"));
    return this.rootResourceAssembler.toResource(node);
}

From source file:org.numenta.nupic.algorithms.Statistic.java

/**
 * Creates and returns a JSON ObjectNode containing this Statistic's data.
 * //from   w w w  .  j  a  v a 2 s . c  o  m
 * @param factory
 * @return
 */
public ObjectNode toJson(JsonNodeFactory factory) {
    ObjectNode distribution = factory.objectNode();
    distribution.put("mean", mean);
    distribution.put("variance", variance);
    distribution.put("stdev", stdev);

    return distribution;
}

From source file:com.redhat.lightblue.metadata.rdbms.converter.Range.java

@Override
public String toString() {
    JsonNodeFactory jsonNodeFactory = JsonNodeFactory.withExactBigDecimals(true);

    ObjectNode objectNode = jsonNodeFactory.objectNode();

    JsonNode jsonNode = from == null ? jsonNodeFactory.nullNode() : jsonNodeFactory.numberNode(from);
    objectNode.set("from", jsonNode);

    jsonNode = to == null ? jsonNodeFactory.nullNode() : jsonNodeFactory.numberNode(to);
    objectNode.set("to", jsonNode);

    return JsonUtils.prettyPrint(objectNode);
}

From source file:org.jongo.NonPojoTest.java

@Test
public void canSaveANewJsonNode() throws Exception {
    JsonNodeFactory factory = new JsonNodeFactory(false);
    ObjectNode node = factory.objectNode();
    node.put("test", "value");

    collection.save(node);/*  www .  ja v a  2s.c o  m*/

    JsonNode result = collection.findOne().as(JsonNode.class);
    assertThat(result.get("_id")).isNotNull();
    assertThat(result.get("test").asText()).isEqualTo("value");
}

From source file:com.cloudbees.clickstack.vertx.VertxConfigurationBuilderTest.java

@Test
public void generateConfiguration() throws Exception {

    Metadata metadata = Metadata.Builder
            .fromStream(Thread.currentThread().getContextClassLoader().getResourceAsStream("metadata-1.json"));
    ObjectMapper mapper = new ObjectMapper();
    JsonNodeFactory nodeFactory = mapper.getNodeFactory();
    VertxConfigurationBuilder builder = new VertxConfigurationBuilder();

    ObjectNode conf = nodeFactory.objectNode();
    builder.fillVertxModuleConfiguration(metadata, nodeFactory, conf);

    mapper.writerWithDefaultPrettyPrinter().writeValue(System.out, conf);

}

From source file:com.axelor.web.MapRest.java

@Path("/geomap/turnover")
@GET/*w w  w  .ja  v  a  2  s  .  c om*/
@Produces(MediaType.APPLICATION_JSON)
public JsonNode getGeoMapData() {

    Map<String, BigDecimal> data = new HashMap<String, BigDecimal>();
    List<? extends SaleOrder> orders = saleOrderRepo.all().filter("self.statusSelect=?", 3).fetch();
    JsonNodeFactory factory = JsonNodeFactory.instance;
    ObjectNode mainNode = factory.objectNode();
    ArrayNode arrayNode = factory.arrayNode();

    ArrayNode labelNode = factory.arrayNode();
    labelNode.add("Country");
    labelNode.add("Turnover");
    arrayNode.add(labelNode);

    for (SaleOrder so : orders) {

        Country country = so.getMainInvoicingAddress().getAddressL7Country();
        BigDecimal value = so.getExTaxTotal();

        if (country != null) {
            String key = country.getName();

            if (data.containsKey(key)) {
                BigDecimal oldValue = data.get(key);
                oldValue = oldValue.add(value);
                data.put(key, oldValue);
            } else {
                data.put(key, value);
            }
        }
    }

    Iterator<String> keys = data.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        ArrayNode dataNode = factory.arrayNode();
        dataNode.add(key);
        dataNode.add(data.get(key));
        arrayNode.add(dataNode);
    }

    mainNode.put("status", 0);
    mainNode.put("data", arrayNode);
    return mainNode;
}

From source file:co.rsk.core.NetworkStateExporter.java

public boolean exportStatus(String outputFile) {
    Repository frozenRepository = this.repository.getSnapshotTo(this.repository.getRoot());

    File dumpFile = new File(outputFile);

    try (FileWriter fw = new FileWriter(dumpFile.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw)) {
        JsonNodeFactory jsonFactory = new JsonNodeFactory(false);
        ObjectNode mainNode = jsonFactory.objectNode();
        for (ByteArrayWrapper address : frozenRepository.getAccountsKeys()) {
            if (!address.equals(new ByteArrayWrapper(ZERO_BYTE_ARRAY))) {
                mainNode.set(Hex.toHexString(address.getData()),
                        createAccountNode(mainNode, address.getData(), frozenRepository));
            }/* ww w.  j a va 2  s . com*/
        }
        ObjectMapper mapper = new ObjectMapper();
        ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
        bw.write(writer.writeValueAsString(mainNode));
        return true;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        panicProcessor.panic("dumpstate", e.getMessage());
        return false;
    }
}