Example usage for com.fasterxml.jackson.databind JsonNode longValue

List of usage examples for com.fasterxml.jackson.databind JsonNode longValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode longValue.

Prototype

public long longValue() 

Source Link

Usage

From source file:com.ning.metrics.serialization.event.SmileEnvelopeEvent.java

public static DateTime getEventDateTimeFromJson(final JsonNode node) {
    final JsonNode eventDateTimeNode = node.get(SMILE_EVENT_DATETIME_TOKEN_NAME);
    return (eventDateTimeNode == null) ? new DateTime() : new DateTime(eventDateTimeNode.longValue());
}

From source file:com.redhat.lightblue.query.Value.java

/**
 * Creates a value from a json node/*w w w.  j  ava2 s.  c  om*/
 *
 * If the node is decimal, double, or float, create s a BigDecimal value. If
 * the node is BigInteger, creates a BigIngeter value. If the node is a long
 * or int, creates a long or int value. If the node is a boolean, creates a
 * boolean value. Otherwise, creates a string value.
 */
public static Value fromJson(JsonNode node) {
    if (node.isValueNode()) {
        Object v = null;
        if (node.isNumber()) {
            if (node.isBigDecimal() || node.isDouble() || node.isFloat()) {
                v = node.decimalValue();
            } else if (node.isBigInteger()) {
                v = node.bigIntegerValue();
            } else if (node.isLong()) {
                v = node.longValue();
            } else {
                v = node.intValue();
            }
        } else if (node.isBoolean()) {
            v = node.booleanValue();
        } else {
            v = node.textValue();
        }
        return new Value(v);
    } else {
        throw Error.get(QueryConstants.ERR_INVALID_VALUE, node.toString());
    }
}

From source file:org.flowable.common.engine.impl.el.function.VariableContainsExpressionFunction.java

public static boolean arrayNodeContains(ArrayNode arrayNode, Object value) {
    Iterator<JsonNode> iterator = arrayNode.iterator();
    while (iterator.hasNext()) {
        JsonNode jsonNode = iterator.next();
        if (value == null && jsonNode.isNull()) {
            return true;
        } else if (value != null) {
            if (value instanceof String && jsonNode.isTextual()
                    && StringUtils.equals(jsonNode.asText(), (String) value)) {
                return true;
            } else if (value instanceof Number && jsonNode.isLong()
                    && jsonNode.longValue() == ((Number) value).longValue()) {
                return true;
            } else if (value instanceof Number && jsonNode.isDouble()
                    && jsonNode.doubleValue() == ((Number) value).doubleValue()) {
                return true;
            } else if (value instanceof Number && jsonNode.isInt()
                    && jsonNode.intValue() == ((Number) value).intValue()) {
                return true;
            } else if (value instanceof Boolean && jsonNode.isBoolean()
                    && jsonNode.booleanValue() == ((Boolean) value).booleanValue()) {
                return true;
            }//  w  w w  . j av a  2 s .c o m
        }
    }
    return false;
}

From source file:com.attribyte.essem.util.Util.java

/**
 * Gets an long value from a node./*from www. j ava  2 s  .co m*/
 * @param node The parent node.
 * @param key The key.
 * @param defaultValue The default value.
 * @return The value or default value.
 */
public static long getLongField(final JsonNode node, final String key, final long defaultValue) {
    JsonNode field = node.get(key);
    if (field != null && field.canConvertToInt()) {
        return field.longValue();
    } else {
        return defaultValue;
    }
}

From source file:com.basistech.yca.JsonNodeFlattener.java

private static void traverse(JsonNode node, String pathSoFar, Dictionary<String, Object> map)
        throws IOException {
    if (!node.isContainerNode()) {
        Object value;/*from  w ww  . j  av  a  2s. co m*/
        if (node.isBigDecimal()) {
            value = node.decimalValue();
        } else if (node.isBigInteger()) {
            value = node.bigIntegerValue();
        } else if (node.isBinary()) {
            value = node.binaryValue();
        } else if (node.isBoolean()) {
            value = node.booleanValue();
        } else if (node.isDouble()) {
            value = node.doubleValue();
        } else if (node.isFloat()) {
            value = node.floatValue();
        } else if (node.isInt()) {
            value = node.intValue();
        } else if (node.isLong()) {
            value = node.longValue();
        } else if (node.isNull()) {
            // NOTE: stupid old Hashtable can't store null values.
            value = NULL;
        } else if (node.isShort()) {
            value = node.shortValue();
        } else if (node.isTextual()) {
            value = node.textValue();
        } else {
            throw new RuntimeException("Unanticipated node " + node);
        }
        map.put(pathSoFar, value);
    } else {
        if (node.isArray()) {
            traverseArray(node, pathSoFar, map);
        } else {
            traverseObject(node, pathSoFar, map);
        }
    }
}

From source file:org.eel.kitchen.jsonschema.keyword.DivisibleByKeywordValidator.java

@Override
protected void validateLong(final ValidationReport report, final JsonNode instance) {
    final long instanceValue = instance.longValue();
    final long longValue = number.longValue();

    final long remainder = instanceValue % longValue;

    if (remainder == 0L)
        return;//  w w  w  .j  a va  2  s.  c o m

    final Message.Builder msg = newMsg().setMessage("number is not a multiple of divisibleBy")
            .addInfo("value", instance).addInfo("divisor", number);
    report.addMessage(msg.build());
}

From source file:org.eel.kitchen.jsonschema.keyword.MinimumKeywordValidator.java

@Override
protected void validateLong(final ValidationReport report, final JsonNode instance) {
    final long instanceValue = instance.longValue();
    final long longValue = number.longValue();

    if (instanceValue > longValue)
        return;//  w  w  w .  j a  va2 s . c  o m

    final Message.Builder msg = newMsg().addInfo(keyword, number).addInfo("found", instance);

    if (instanceValue < longValue) {
        msg.setMessage("number is lower than the required minimum");
        report.addMessage(msg.build());
        return;
    }

    if (!exclusive)
        return;

    msg.addInfo("exclusiveMinimum", nodeFactory.booleanNode(true))
            .setMessage("number is not strictly greater than the required " + "minimum");
    report.addMessage(msg.build());
}

From source file:org.eel.kitchen.jsonschema.keyword.MaximumKeywordValidator.java

@Override
protected void validateLong(final ValidationReport report, final JsonNode instance) {
    final long instanceValue = instance.longValue();
    final long longValue = number.longValue();

    if (instanceValue < longValue)
        return;//from  w w w  .  jav  a2s.  co m

    final Message.Builder msg = newMsg().addInfo(keyword, number).addInfo("found", instance);

    if (instanceValue > longValue) {
        msg.setMessage("number is greater than the required maximum");
        report.addMessage(msg.build());
        return;
    }

    if (!exclusive)
        return;

    msg.setMessage("number is not strictly lower than the required maximum").addInfo("exclusiveMaximum",
            nodeFactory.booleanNode(true));
    report.addMessage(msg.build());
}

From source file:com.github.fge.jsonschema.keyword.validator.helpers.DivisorValidator.java

@Override
protected final void validateLong(final ProcessingReport report, final MessageBundle bundle,
        final FullData data) throws ProcessingException {
    final JsonNode node = data.getInstance().getNode();
    final long instanceValue = node.longValue();
    final long longValue = number.longValue();

    final long remainder = instanceValue % longValue;

    if (remainder == 0L)
        return;/*w w  w.ja va 2s . c om*/

    report.error(newMsg(data, bundle, "err.common.divisor.nonZeroRemainder").putArgument("value", node)
            .putArgument("divisor", number));
}

From source file:com.github.fge.jsonschema.keyword.validator.common.MaximumValidator.java

@Override
protected void validateLong(final ProcessingReport report, final MessageBundle bundle, final FullData data)
        throws ProcessingException {
    final JsonNode instance = data.getInstance().getNode();
    final long instanceValue = instance.longValue();
    final long longValue = number.longValue();

    if (instanceValue < longValue)
        return;/*  w w w .ja  va2  s.c  o m*/

    if (instanceValue > longValue) {
        report.error(newMsg(data, bundle, "err.common.maximum.tooLarge").putArgument(keyword, number)
                .putArgument("found", instance));
        return;
    }

    if (!exclusive)
        return;

    report.error(newMsg(data, bundle, "err.common.maximum.notExclusive").putArgument(keyword, number)
            .put("exclusiveMaximum", BooleanNode.TRUE));
}