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

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

Introduction

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

Prototype

public long asLong(long paramLong) 

Source Link

Usage

From source file:org.apache.usergrid.android.sdk.utils.JsonUtils.java

public static Long getLongProperty(Map<String, JsonNode> properties, String name) {
    JsonNode value = properties.get(name);
    if (value != null) {
        return value.asLong(0);
    }//from   w  ww.  j  a  va 2s .  c  om
    return null;
}

From source file:io.gravitee.definition.jackson.datatype.api.deser.FailoverDeserializer.java

@Override
public Failover deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);

    Failover failover = new Failover();

    final JsonNode casesNode = node.get("cases");
    if (casesNode != null) {
        if (casesNode.isArray()) {
            List<FailoverCase> cases = new ArrayList<>();

            casesNode.elements().forEachRemaining(
                    jsonNode -> cases.add(FailoverCase.valueOf(jsonNode.asText().toUpperCase())));

            failover.setCases(cases.toArray(new FailoverCase[cases.size()]));
        } else {//from   ww w.j  a  v  a2s .  c  o m
            failover.setCases(new FailoverCase[] { FailoverCase.valueOf(casesNode.asText().toUpperCase()) });
        }
    }

    JsonNode maxAttemptsNode = node.get("maxAttempts");
    if (maxAttemptsNode != null) {
        int maxAttempts = maxAttemptsNode.asInt(Failover.DEFAULT_MAX_ATTEMPTS);
        failover.setMaxAttempts(maxAttempts);
    } else {
        failover.setMaxAttempts(Failover.DEFAULT_MAX_ATTEMPTS);
    }

    JsonNode retryTimeoutNode = node.get("retryTimeout");
    if (retryTimeoutNode != null) {
        long retryTimeout = retryTimeoutNode.asLong(Failover.DEFAULT_RETRY_TIMEOUT);
        failover.setRetryTimeout(retryTimeout);
    } else {
        failover.setRetryTimeout(Failover.DEFAULT_RETRY_TIMEOUT);
    }

    return failover;
}

From source file:io.gravitee.definition.jackson.datatype.api.deser.HttpClientOptionsDeserializer.java

@Override
public HttpClientOptions deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);

    HttpClientOptions httpClientOptions = new HttpClientOptions();

    JsonNode connectTimeoutNode = node.get("connectTimeout");
    if (connectTimeoutNode != null) {
        long connectTimeout = connectTimeoutNode.asLong(HttpClientOptions.DEFAULT_CONNECT_TIMEOUT);
        httpClientOptions.setConnectTimeout(connectTimeout);
    } else {/*from   w  w w .  j  a  v  a  2 s  .c o  m*/
        httpClientOptions.setConnectTimeout(HttpClientOptions.DEFAULT_CONNECT_TIMEOUT);
    }

    JsonNode readTimeoutNode = node.get("readTimeout");
    if (readTimeoutNode != null) {
        long readTimeout = readTimeoutNode.asLong(HttpClientOptions.DEFAULT_READ_TIMEOUT);
        httpClientOptions.setReadTimeout(readTimeout);
    } else {
        httpClientOptions.setReadTimeout(HttpClientOptions.DEFAULT_READ_TIMEOUT);
    }

    JsonNode idleTimeoutNode = node.get("idleTimeout");
    if (idleTimeoutNode != null) {
        long idleTimeout = idleTimeoutNode.asLong(HttpClientOptions.DEFAULT_IDLE_TIMEOUT);
        httpClientOptions.setIdleTimeout(idleTimeout);
    } else {
        httpClientOptions.setIdleTimeout(HttpClientOptions.DEFAULT_IDLE_TIMEOUT);
    }

    JsonNode keepAliveNode = node.get("keepAlive");
    if (keepAliveNode != null) {
        boolean keepAlive = keepAliveNode.asBoolean(HttpClientOptions.DEFAULT_KEEP_ALIVE);
        httpClientOptions.setKeepAlive(keepAlive);
    } else {
        httpClientOptions.setKeepAlive(HttpClientOptions.DEFAULT_KEEP_ALIVE);
    }

    JsonNode pipeliningNode = node.get("pipelining");
    if (pipeliningNode != null) {
        boolean pipelining = pipeliningNode.asBoolean(HttpClientOptions.DEFAULT_PIPELINING);
        httpClientOptions.setPipelining(pipelining);
    } else {
        httpClientOptions.setPipelining(HttpClientOptions.DEFAULT_PIPELINING);
    }

    JsonNode maxConcurrentConnectionsNode = node.get("maxConcurrentConnections");
    if (maxConcurrentConnectionsNode != null) {
        int maxConcurrentConnections = maxConcurrentConnectionsNode
                .asInt(HttpClientOptions.DEFAULT_MAX_CONCURRENT_CONNECTIONS);
        httpClientOptions.setMaxConcurrentConnections(maxConcurrentConnections);
    } else {
        httpClientOptions.setMaxConcurrentConnections(HttpClientOptions.DEFAULT_MAX_CONCURRENT_CONNECTIONS);
    }

    JsonNode useCompressionNode = node.get("useCompression");
    if (useCompressionNode != null) {
        boolean useCompression = useCompressionNode.asBoolean(HttpClientOptions.DEFAULT_USE_COMPRESSION);
        httpClientOptions.setUseCompression(useCompression);
    } else {
        httpClientOptions.setUseCompression(HttpClientOptions.DEFAULT_USE_COMPRESSION);
    }

    return httpClientOptions;
}

From source file:org.graylog2.inputs.codecs.GelfCodec.java

private static long longValue(final JsonNode json, final String fieldName) {
    if (json != null) {
        final JsonNode value = json.get(fieldName);

        if (value != null) {
            return value.asLong(-1L);
        }//from w ww. ja va 2s  .  c om
    }
    return -1L;
}