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

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

Introduction

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

Prototype

public BinaryNode binaryNode(byte[] paramArrayOfByte) 

Source Link

Usage

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

/** Utility that goes from Writable to JsonNode
 * @param x// ww  w.j a  v a2 s.  co 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.BinaryType.java

@Override
public JsonNode toJson(JsonNodeFactory factory, Object obj) {
    return factory.binaryNode((byte[]) cast(obj));
}

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 av  a2 s  .  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();
}