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

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

Introduction

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

Prototype

public NumericNode numberNode(BigInteger paramBigInteger) 

Source Link

Usage

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  w w. j  a  v a2  s.co m
            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.PredefinedFields.java

/**
 * Updates all array size values at the subtree rooted at the given object
 * node/*ww  w. j a  va2  s  . c  om*/
 *
 * @param factory Node factory
 * @param node All array size fields under this subtree will be updated
 */
public static void updateArraySizes(JsonNodeFactory factory, ObjectNode node) {
    Map<String, JsonNode> sizes = new HashMap<>();
    for (Iterator<Map.Entry<String, JsonNode>> itr = node.fields(); itr.hasNext();) {
        Map.Entry<String, JsonNode> field = itr.next();
        JsonNode value = field.getValue();
        if (value instanceof ArrayNode) {
            sizes.put(field.getKey() + "#", factory.numberNode(((ArrayNode) value).size()));
        }
        updateArraySizes(factory, value);
    }
    for (Map.Entry<String, JsonNode> entry : sizes.entrySet()) {
        node.set(entry.getKey(), entry.getValue());
    }
}

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

/** Utility that goes from various MongoDB artefacts to JsonNode
 * @param x/*  w w  w.  j  a va  2s. co  m*/
 * @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 av  a  2  s . c  o m
 * @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:com.redhat.lightblue.metadata.types.DoubleType.java

@Override
public JsonNode toJson(JsonNodeFactory factory, Object obj) {
    return factory.numberNode((Double) cast(obj));
}

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

@Override
public JsonNode toJson(JsonNodeFactory factory, Object obj) {
    return factory.numberNode((Long) cast(obj));
}

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

@Override
public JsonNode toJson(JsonNodeFactory factory, Object obj) {
    return factory.numberNode((BigInteger) cast(obj));
}

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

@Override
public JsonNode toJson(JsonNodeFactory factory, Object obj) {
    return factory.numberNode((BigDecimal) cast(obj));
}

From source file:com.redhat.smonkey.RndLong.java

@Override
public JsonNode generate(JsonNodeFactory nodeFactory, JsonNode data, Monkey mon) {
    long min = Utils.asLong(data.get("min"), Long.MIN_VALUE);
    long max = Utils.asLong(data.get("max"), Long.MAX_VALUE);
    long x = Utils.rndl(min, max);
    return nodeFactory.numberNode(x);
}

From source file:com.redhat.smonkey.RndInt.java

@Override
public JsonNode generate(JsonNodeFactory nodeFactory, JsonNode data, Monkey mon) {
    int min = Utils.asInt(data.get("min"), Integer.MIN_VALUE);
    int max = Utils.asInt(data.get("max"), Integer.MAX_VALUE);
    long x = Utils.rndi(min, max);
    return nodeFactory.numberNode(x);
}