List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:org.apache.usergrid.java.client.utils.JsonUtils.java
@Nullable @SuppressWarnings("unchecked") public static <T> T getProperty(@NotNull final Map<String, JsonNode> properties, @NotNull final String name) { JsonNode value = properties.get(name); if (value == null) { return null; } else if (value instanceof TextNode) { return (T) value.asText(); } else if (value instanceof LongNode) { Long valueLong = value.asLong(); return (T) valueLong; } else if (value instanceof BooleanNode) { Boolean valueBoolean = value.asBoolean(); return (T) valueBoolean; } else if (value instanceof IntNode) { Integer valueInteger = value.asInt(); return (T) valueInteger; } else if (value instanceof FloatNode) { return (T) Float.valueOf(value.toString()); } else {//from w w w . j a v a 2 s . c o m return (T) value; } }
From source file:com.redhat.lightblue.query.RValueExpression.java
/** * Parses an rvalue from a json node.//from w w w .ja v a 2 s. c o m */ public static RValueExpression fromJson(JsonNode node) { if (node instanceof ObjectNode) { if (node.size() == 1) { JsonNode path = node.get("$valueof"); if (path != null && path.isValueNode()) { return new RValueExpression(new Path(path.asText())); } } else { return new RValueExpression(); } } else if (node.isValueNode()) { if (node.asText().equals("$null")) { return new RValueExpression(RValueType._null); } else { return new RValueExpression(Value.fromJson(node)); } } throw Error.get(QueryConstants.ERR_INVALID_RVALUE_EXPRESSION, node.toString()); }
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);//ww 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:de.thingweb.typesystem.jsonschema.JsonSchemaType.java
private static boolean isOfType(String type, List<String> types) { boolean isOfType = false; try {//from w w w . ja va 2s.c o m // TODO use JSON schema parser if (type != null) { ObjectMapper mapper = new ObjectMapper(); JsonNode valueType = mapper.readValue(new StringReader(type), JsonNode.class); if (valueType != null) { JsonNode value = valueType.findValue("type"); if (value != null) { isOfType = types.contains(value.asText()); } } } } catch (Exception e) { // failure --> no JSON schema } return isOfType; }
From source file:com.baasbox.commands.CollectionsResource.java
private static String extractCollectionName(JsonNode command) throws CommandParsingException { JsonNode node = command.get(ScriptCommand.PARAMS); if (!node.isTextual()) { throw new CommandParsingException(command, "expeceted params to be the name of a collection"); }// ww w . j ava 2 s .c o m return node.asText(); }
From source file:com.vaushell.superpipes.tools.scribe.OAuthClient.java
/** * Convert a string node to a string./*from w w w . j a va 2 s .c o m*/ * * @param node the node * @return a string or null if node is null */ protected static String convertNodeToString(final JsonNode node) { if (node == null) { return null; } else { return node.asText(); } }
From source file:bear.plugins.nodejs.NodeJsPlugin.java
private static String getString(JsonNode node, String field, String _default) { JsonNode name = node.get(field); if (name != null) return name.asText(); return _default; }
From source file:com.pros.jsontransform.sort.ArraySortAbstract.java
static int compareValueNodes(JsonNode value1, JsonNode value2) { int result = 0; if (value1.isNumber() && value2.isNumber()) { result = Double.compare(value1.asDouble(), value2.asDouble()); } else if (value1.isTextual() && value2.isTextual()) { result = value1.asText().compareTo(value2.asText()); }//w w w .j av a 2 s .c o m return result; }
From source file:com.htmlhifive.pitalium.it.util.ItUtils.java
/** * ?JSON???????//from w w w . j a v a 2s. com * * @param results * @param capabilities */ public static JsonNode getCurrentScreenshotResultJson(String methodName, JsonNode results, PtlCapabilities capabilities) { for (JsonNode jn : results.get("screenshotResults")) { JsonNode capabilitiesNode = jn.get("capabilities"); String platform = capabilities.getPlatform() != null ? capabilities.getPlatform().toString() : ""; if (methodName.equals(jn.get("testMethod").asText()) && capabilities.getBrowserName().equals(capabilitiesNode.get("browserName").asText())) { if (platform.equals("") || platform.endsWith(capabilitiesNode.get("platform").asText())) { JsonNode version = capabilitiesNode.get("version"); if (version == null) { if (StringUtils.isEmpty(capabilities.getVersion())) { return jn; } } else { if (version.asText().equals(capabilities.getVersion())) { return jn; } } } } } return null; }
From source file:io.coala.eve3.EveUtil.java
/** */ @SafeVarargs//from w w w .j av a 2 s. com public static final <T extends Agent> T valueOf(final String id, final Class<T> agentType, final Map.Entry<String, ? extends JsonNode>... parameters) { @SuppressWarnings("unchecked") final EveAgentConfig cfg = ConfigFactory.create(EveAgentConfig.class, EveAgentConfig.DEFAULT_VALUES, map(entry(EveAgentConfig.AGENT_CLASS_KEY, agentType.getName()), entry(EveAgentConfig.AGENT_ID_KEY, id), entry(EveAgentConfig.AGENT_ID_KEY, id))); final InputStream is = cfg.agentConfigStream(); if (is != null) { final Config config = YamlReader.load(is).expand(); try { is.close(); } catch (final IOException ignore) { // empty } for (final JsonNode agent : (ArrayNode) config.get("agents")) { final JsonNode idNode = agent.get("id"); if (idNode != null && !idNode.asText().equals(id)) continue; LOG.info("Creating agent " + id + " from config at " + cfg.agentConfigUri()); return valueOf(new AgentConfig((ObjectNode) agent), agentType, parameters); } } LOG.info("No config for agent " + id + " found at: " + cfg.agentConfigUri() + ". Using default config"); return valueOf(cfg.agentConfig(), agentType, parameters); }