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

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


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


public TextNode textNode(String paramString) 

Source Link


From source file:io.fabric8.collector.elasticsearch.JsonNodes.java

 * Sets a property on a node/* w ww . ja va 2  s  . com*/
public static boolean set(JsonNode node, String name, String text) {
    JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    return set(node, name, nodeFactory.textNode(text));

From source file:com.ikanow.aleph2.v1.document_db.utils.JsonNodeBsonUtils.java

/** Utility that goes from various MongoDB artefacts to JsonNode
 * @param x//from w ww.ja v  a 2s. c  om
 * @return
protected static JsonNode transform(Object x, JsonNodeFactory nc) {
    if (null == x) { // missing => missing
        return null;
    } else if (x instanceof ObjectId) {
        return nc.textNode(((ObjectId) x).toString());
    } else if (x instanceof Boolean) {
        return nc.booleanNode(((Boolean) x));
    } else if (x instanceof String) {
        return nc.textNode(((String) x));
    } else if (x instanceof Date) {
        return nc.numberNode(((Date) x).getTime());
    } else if (x instanceof Double) {
        return nc.numberNode(((Double) x));
    } else if (x instanceof Float) {
        return nc.numberNode(((Float) x));
    } else if (x instanceof Long) {
        return nc.numberNode(((Long) x));
    } else if (x instanceof Integer) {
        return nc.numberNode(((Integer) x));
    } else if (x instanceof byte[]) {
        return nc.binaryNode(((byte[]) x));
    } else if (x instanceof BasicBSONList) {
        // (don't do this lazily, construct entire thing once requested)
        return new ArrayNodeWrapper(nc, (BasicBSONList) x);
    } else if (x instanceof BSONObject) { // recurse! (ish)
        return new ObjectNodeWrapper(nc, (BSONObject) x);
    } else
        return nc.nullNode();

From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.JsonNodeWritableUtils.java

/** Utility that goes from Writable to JsonNode
 * @param x//from  w  w  w . j  a v a 2s  .com
 * @return
protected static JsonNode transform(Object x, JsonNodeFactory nc) {
    if (null == x) {
        return null; //(missing->missing)
    } else if (x instanceof NullWritable) {
        return nc.nullNode();
    } else if (x instanceof BooleanWritable) {
        return nc.booleanNode(((BooleanWritable) x).get());
    } else if (x instanceof Text) {
        return nc.textNode(((Text) x).toString());
    } else if (x instanceof ByteWritable) {
        return nc.binaryNode(new byte[] { ((ByteWritable) x).get() });
    } else if (x instanceof IntWritable) {
        return nc.numberNode(((IntWritable) x).get());
    } else if (x instanceof VIntWritable) {
        return nc.numberNode(((VIntWritable) x).get());
    } else if (x instanceof LongWritable) {
        return nc.numberNode(((LongWritable) x).get());
    } else if (x instanceof VLongWritable) {
        return nc.numberNode(((VLongWritable) x).get());
    } else if (x instanceof BytesWritable) {
        return nc.binaryNode(((BytesWritable) x).getBytes());
    } else if (x instanceof DoubleWritable) {
        return nc.numberNode(((DoubleWritable) x).get());
    } else if (x instanceof FloatWritable) {
        return nc.numberNode(((FloatWritable) x).get());
    } else if (x instanceof ArrayWritable) {
        Writable[] xx = ((ArrayWritable) x).get();
        // (don't do this lazily, construct entire thing once requested)
        return new ArrayNodeWrapper(nc, xx);
    } else if (x instanceof MapWritable) { // recurse! (ish)
        return new ObjectNodeWrapper(nc, (MapWritable) x);
    } else
        return nc.nullNode();

From source file:org.teavm.flavour.json.test.TeaVMJSONRunner.java

public static final JsonNode convert(JsonNodeFactory nf, Node node) {
    if (node.isNull()) {
        return nf.nullNode();
    } else if (node.isBoolean()) {
        BooleanNode booleanNode = (BooleanNode) node;
        return nf.booleanNode(booleanNode.getValue());
    } else if (node.isNumber()) {
        NumberNode numberNode = (NumberNode) node;
        if (numberNode.isInt()) {
            return nf.numberNode(numberNode.getIntValue());
        } else {//from w ww . j  a  v  a  2  s  .com
            return nf.numberNode(numberNode.getValue());
    } else if (node.isString()) {
        StringNode stringNode = (StringNode) node;
        return nf.textNode(stringNode.getValue());
    } else if (node.isArray()) {
        ArrayNode result = nf.arrayNode();
        org.teavm.flavour.json.tree.ArrayNode source = (org.teavm.flavour.json.tree.ArrayNode) node;
        for (int i = 0; i < source.size(); ++i) {
            result.add(convert(nf, source.get(i)));
        return result;
    } else if (node.isObject()) {
        com.fasterxml.jackson.databind.node.ObjectNode result = nf.objectNode();
        ObjectNode objectNode = (ObjectNode) node;
        for (String key : objectNode.allKeys()) {
            result.replace(key, convert(nf, objectNode.get(key)));
        return result;
    } else {
        throw new IllegalArgumentException("Can't convert this JSON node");

From source file:com.redhat.lightblue.metadata.types.StringType.java

public JsonNode toJson(JsonNodeFactory factory, Object obj) {
    return factory.textNode((String) cast(obj));

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

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());
    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);/*www . j av  a2  s. c  o m*/

From source file:com.redhat.lightblue.metadata.types.DateType.java

public JsonNode toJson(JsonNodeFactory factory, Object obj) {
    return factory.textNode(getDateFormat().format((Date) cast(obj)));

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
 *///from w  w  w .j a v  a 2  s .  co m
@GetMapping(produces = MediaTypes.HAL_JSON_VALUE)
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:io.fabric8.kubernetes.api.KubernetesHelper.java

protected static JsonNode findOrCreateConfig(Object[] objects) {
    for (Object object : objects) {
        if (object instanceof JsonNode) {
            JsonNode jsonNode = (JsonNode) object;
            JsonNode items = jsonNode.get("items");
            if (items != null && items.isArray()) {
                return jsonNode;
            }/*from  ww  w  .j a va2  s.  c om*/

    // lets create a new list
    JsonNodeFactory factory = createNodeFactory();
    ObjectNode config = factory.objectNode();
    config.set("apiVersion", factory.textNode("v1beta2"));
    config.set("kind", factory.textNode("List"));
    config.set("items", factory.arrayNode());
    return config;

From source file:org.kiji.rest.TestKijiRestEntityId.java

public void testShouldCreateListsOfEntityIds() throws Exception {
    final TableLayoutDesc desc = KijiTableLayouts.getLayout("org/kiji/rest/layouts/rkf_hashprefixed.json");
    final KijiTableLayout layout = KijiTableLayout.newLayout(desc);
    final EntityIdFactory factory = EntityIdFactory.getFactory(layout);
    final byte[] rowKey = Bytes.toBytes(UNUSUAL_STRING_EID);
    final EntityId originalEid = factory.getEntityIdFromHBaseRowKey(rowKey);

    // test the creation of entity ids from raw hbase rowkey
    final KijiRestEntityId restEid1 = KijiRestEntityId.createFromUrl(
            String.format("hbase_hex=%s", new String(Hex.encodeHex(originalEid.getHBaseRowKey()))), layout);
    final KijiRestEntityId restEid2 = KijiRestEntityId.createFromUrl(
            String.format("hbase=%s", Bytes.toStringBinary(originalEid.getHBaseRowKey())), layout);

    final JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(true);
    final JsonNode hbaseHexStringNode = jsonNodeFactory
            .textNode(String.format("hbase_hex=%s", new String(Hex.encodeHex(originalEid.getHBaseRowKey()))));
    final JsonNode hbaseBinaryStringNode = jsonNodeFactory
            .textNode(String.format("hbase_hex=%s", new String(Hex.encodeHex(originalEid.getHBaseRowKey()))));
    ArrayNode hbaseListNode = jsonNodeFactory.arrayNode();

    final List<KijiRestEntityId> restEidList1 = KijiRestEntityId.createListFromUrl(hbaseListNode.toString(),
            layout);/*from   www . j  av  a 2  s .c o  m*/

    assertEquals(restEid1.resolve(layout), restEidList1.get(0).resolve(layout));
    assertEquals(restEid2.resolve(layout), restEidList1.get(1).resolve(layout));

    // test the creation of entity ids from various json strings
    final KijiRestEntityId restEid3 = KijiRestEntityId.createFromUrl("[\"Hello\",\"World\"]", layout);
    final List<KijiRestEntityId> restEidList3 = KijiRestEntityId.createListFromUrl("[[\"Hello\",\"World\"]]",
    final KijiRestEntityId restEid4 = KijiRestEntityId.createFromUrl("[[],\"World\"]", layout);
    final List<KijiRestEntityId> restEidList4 = KijiRestEntityId
            .createListFromUrl("[[[],\"World\"],[\"Hello\",\"World\"]]", layout);

    assertEquals(restEid3.resolve(layout), restEidList3.get(0).resolve(layout));
    assertEquals(restEid4.getStringEntityId(), restEidList4.get(0).getStringEntityId());
    assertEquals(1, restEidList3.size());
    assertEquals(2, restEidList4.size());