List of usage examples for com.fasterxml.jackson.databind JsonNode asLong
public long asLong()
From source file:com.redhat.lightblue.ExecutionOptions.java
/** * Parses execution options from a json object. Unrecognized elements are * ignored.//from ww w. ja v a2 s .co m */ public static ExecutionOptions fromJson(ObjectNode node) { ExecutionOptions ret = new ExecutionOptions(); JsonNode x = node.get("timeLimit"); if (x != null) { ret.timeLimit = x.asLong(); } x = node.get("asynchronous"); if (x != null) { ret.asynchronous = x.asLong(); } return ret; }
From source file:com.squarespace.template.JsonUtils.java
/** * Compare two JsonNode objects and return an integer. * * @return a negative integer, zero, or a positive integer as this object * is less than, equal to, or greater than the specified object. *///from w ww . java2 s . c o m public static int compare(JsonNode left, JsonNode right) { if (left.isLong() || left.isInt()) { return Long.compare(left.asLong(), right.asLong()); } else if (left.isDouble() || left.isFloat()) { return Double.compare(left.asDouble(), right.asDouble()); } else if (left.isTextual()) { return left.asText().compareTo(right.asText()); } else if (left.isBoolean()) { return Boolean.compare(left.asBoolean(), right.asBoolean()); } // Not comparable in a relative sense, default to equals. return left.equals(right) ? 0 : -1; }
From source file:com.redhat.smonkey.Utils.java
public static Long asLong(JsonNode value, Long def) { return value == null ? def : value.asLong(); }
From source file:org.jboss.aerogear.sync.server.netty.ConfigReader.java
private static StandaloneConfig parseProperties(final JsonNode json) { final Builder b = StandaloneConfig.host(json.get("host").asText()); b.port(json.get("port").asInt()); final JsonNode gcm = json.get("gcm"); if (gcm != null) { final JsonNode enabled = gcm.get("enabled"); if (enabled != null && enabled.asBoolean()) { b.gcmEnabled();//w w w . j a v a 2 s .c o m } final JsonNode gcmHost = gcm.get("host"); if (gcmHost != null) { b.gcmHost(gcmHost.asText()); } final JsonNode gcmPort = gcm.get("port"); if (gcmPort != null) { b.gcmPort(gcmPort.asInt()); } final JsonNode gcmSenderId = gcm.get("senderId"); if (gcmSenderId != null) { b.gcmSenderId(gcmSenderId.asLong()); } final JsonNode gcmApiKey = gcm.get("apiKey"); if (gcmApiKey != null) { b.gcmApiKey(gcmApiKey.asText()); } } return b.build(); }
From source file:org.jboss.aerogear.webpush.standalone.ConfigReader.java
private static WebPushServerConfig parseWebPushProperties(final JsonNode json) { final JsonNode host = json.get("host"); final JsonNode port = json.get("port"); final Builder builder = DefaultWebPushConfig.create(host.asText(), port.asInt()); final JsonNode password = json.get("password"); if (password != null) { builder.password(password.asText()); }/*from www.j a v a 2 s . c om*/ final JsonNode cert = json.get("cert"); if (cert != null) { builder.cert(cert.asText()); } final JsonNode privateKey = json.get("privateKey"); if (privateKey != null) { builder.privateKey(privateKey.asText()); } final JsonNode endpointHost = json.get("endpoint-host"); if (endpointHost != null) { builder.endpointHost(endpointHost.asText()); } final JsonNode endpointPort = json.get("endpoint-port"); if (endpointPort != null) { builder.endpointPort(endpointPort.asInt()); } final JsonNode endpointTls = json.get("endpoint-tls"); if (endpointTls != null) { builder.endpointTls(endpointTls.asBoolean()); } final JsonNode subscriptionMaxAge = json.get("subscription-max-age"); if (subscriptionMaxAge != null) { builder.subscriptionMaxAge(subscriptionMaxAge.asLong()); } return builder.build(); }
From source file:com.amazonaws.services.iot.client.shadow.AwsIotJsonDeserializer.java
public static long deserializeVersion(AbstractAwsIotDevice device, String jsonState) throws IOException { ObjectMapper jsonObjectMapper = device.getJsonObjectMapper(); JsonNode node = jsonObjectMapper.readTree(jsonState); if (node == null) { throw new IOException("Invalid shadow document received for " + device.getThingName()); }//from w w w. j av a 2s .com JsonNode versionNode = node.get("version"); if (versionNode == null) { throw new IOException("Missing version field from shadow document for " + device.getThingName()); } return versionNode.asLong(); }
From source file:com.liferay.sync.engine.util.SyncSystemTestUtil.java
public static long getGuestGroupId(long syncAccountId) throws Exception { if (_guestGroupId > 0) { return _guestGroupId; }// www . ja v a 2 s . c om Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("companyId", getCompanyId(syncAccountId)); parameters.put("name", "Guest"); Session session = SessionManager.getSession(syncAccountId); HttpResponse httpResponse = session.executePost("/group/get-group", parameters); HttpEntity httpEntity = httpResponse.getEntity(); String response = EntityUtils.toString(httpEntity); ObjectMapper mapper = new ObjectMapper(); JsonNode rootJsonNode = mapper.readTree(response); JsonNode groupIdJsonNode = rootJsonNode.get("groupId"); _guestGroupId = groupIdJsonNode.asLong(); return _guestGroupId; }
From source file:com.liferay.sync.engine.util.SyncSystemTestUtil.java
protected static long getCompanyId(long syncAccountId) throws Exception { if (_companyId > 0) { return _companyId; }/*from www . j a v a 2 s . c o m*/ Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("virtualHost", "localhost"); Session session = SessionManager.getSession(syncAccountId); HttpResponse httpResponse = session.executePost("/company/get-company-by-virtual-host", parameters); HttpEntity httpEntity = httpResponse.getEntity(); String response = EntityUtils.toString(httpEntity); ObjectMapper mapper = new ObjectMapper(); JsonNode rootJsonNode = mapper.readTree(response); JsonNode companyIdJsonNode = rootJsonNode.get("companyId"); _companyId = companyIdJsonNode.asLong(); return _companyId; }
From source file:org.jboss.aerogear.simplepush.server.netty.standalone.ConfigReader.java
private static SockJsConfig parseSockJsProperties(final JsonNode json) { final JsonNode prefixNode = json.get("sockjs-prefix"); final String prefix = prefixNode != null ? prefixNode.asText() : "/simplepush"; final org.jboss.aerogear.io.netty.handler.codec.sockjs.SockJsConfig.Builder builder = SockJsConfig .withPrefix(prefix);//from w w w. j a v a2 s . c o m final JsonNode cookiesNeeded = json.get("sockjs-cookies-needed"); if (cookiesNeeded != null && cookiesNeeded.asBoolean()) { builder.cookiesNeeded(); } final JsonNode sockjsUrl = json.get("sockjs-url"); if (sockjsUrl != null) { builder.sockJsUrl(sockjsUrl.asText()); } final JsonNode sessionTimeout = json.get("sockjs-session-timeout"); if (sessionTimeout != null) { builder.sessionTimeout(sessionTimeout.asLong()); } final JsonNode heartbeatInterval = json.get("sockjs-heartbeat-interval"); if (heartbeatInterval != null) { builder.heartbeatInterval(heartbeatInterval.asLong()); } final JsonNode maxStreamingBytesSize = json.get("sockjs-max-streaming-bytes-size"); if (maxStreamingBytesSize != null) { builder.maxStreamingBytesSize(maxStreamingBytesSize.asInt()); } final JsonNode keystore = json.get("sockjs-keystore"); if (keystore != null) { builder.keyStore(keystore.asText()); } final JsonNode keystorePassword = json.get("sockjs-keystore-password"); if (keystorePassword != null) { builder.keyStorePassword(keystorePassword.asText()); } final JsonNode tls = json.get("sockjs-tls"); if (tls != null) { builder.tls(tls.asBoolean()); } final JsonNode websocketEnable = json.get("sockjs-websocket-enable"); if (websocketEnable != null && !websocketEnable.asBoolean()) { builder.disableWebSocket(); } final JsonNode websocketHeartbeatInterval = json.get("sockjs-websocket-heartbeat-interval"); if (websocketHeartbeatInterval != null) { builder.webSocketHeartbeatInterval(websocketHeartbeatInterval.asLong()); } final JsonNode websocketProtocols = json.get("sockjs-websocket-protocols"); if (websocketProtocols != null) { builder.webSocketProtocols(websocketProtocols.asText().split(",")); } return builder.build(); }
From source file:org.jboss.aerogear.simplepush.server.netty.standalone.ConfigReader.java
private static SimplePushServerConfig parseSimplePushProperties(final JsonNode json) { final JsonNode host = json.get("host"); final JsonNode port = json.get("port"); final Builder builder = DefaultSimplePushConfig.create(host.asText(), port.asInt()); final JsonNode password = json.get("password"); if (password != null) { builder.password(password.asText()); }// w w w .j ava 2 s.c o m final JsonNode useragentReaperTimeout = json.get("useragent-reaper-timeout"); if (useragentReaperTimeout != null) { builder.userAgentReaperTimeout(useragentReaperTimeout.asLong()); } final JsonNode endpointHost = json.get("endpoint-host"); if (endpointHost != null) { builder.endpointHost(endpointHost.asText()); } final JsonNode endpointPort = json.get("endpoint-port"); if (endpointPort != null) { builder.endpointPort(endpointPort.asInt()); } final JsonNode endpointTls = json.get("endpoint-tls"); if (endpointTls != null) { builder.endpointTls(endpointTls.asBoolean()); } final JsonNode endpointPrefix = json.get("endpoint-prefix"); if (endpointPrefix != null) { builder.endpointPrefix(endpointPrefix.asText()); } final JsonNode ackInterval = json.get("ack-interval"); if (ackInterval != null) { builder.ackInterval(ackInterval.asLong()); } final JsonNode notifierMaxThreads = json.get("notifier-max-threads"); if (notifierMaxThreads != null) { builder.notifierMaxThreads(notifierMaxThreads.asInt()); } return builder.build(); }