List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java
/** * Return the string value of an optional child node. * <p>/* www . ja va2s . c o m*/ * Check the parent node for the named child, if found return the string contents of the child node, return null otherwise. * * @param parentNode The node to check. * @param name Name of the optional child node. * @return Text value of child node, if found, null otherwise. */ public static String getOptionalStringValue(JsonNode parentNode, String name) { JsonNode childNode = parentNode.get(name); if (null == childNode) { return null; } else { return childNode.textValue(); } }
From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java
/** * Return the integer value of an optional child node. * <p>//from w ww .j av a2 s . c o m * Check the parent node for the named child, if found return the integer contents of the child node, return null otherwise. * * @param parentNode The node to check * @param name The name of the optional child. * @return Integer value of the child node if present, null otherwise. */ public static Integer getOptionalIntegerValue(JsonNode parentNode, String name) { JsonNode childNode = parentNode.get(name); if (null == childNode) { return null; } else { return childNode.asInt(); } }
From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java
/** * Return the long value of an optional child node. * <p>//ww w . j a va2s . co m * Check the parent node for the named child, if found return the long contents of the child node, return null otherwise. * * @param parentNode The node to check * @param name The name of the optional child. * @return Long value of the child node if present, null otherwise. */ public static Long getOptionalLongValue(JsonNode parentNode, String name) { JsonNode childNode = parentNode.get(name); if (null == childNode) { return null; } else { return childNode.asLong(); } }
From source file:com.basistech.yca.JsonNodeFlattener.java
private static void traverseArray(JsonNode node, String pathSoFar, Dictionary<String, Object> map) throws IOException { for (int nodeIndex = 0; nodeIndex < node.size(); nodeIndex++) { String path = pathSoFar + "[" + nodeIndex + "]"; traverse(node.get(nodeIndex), path, map); }//w w w .j a va 2 s. c o m }
From source file:org.bndtools.rt.repository.marshall.CapReqJson.java
private static CapReqBuilder parseCapReq(JsonNode reqNode) throws IllegalArgumentException { String namespace = getRequiredField(reqNode, "ns").asText(); CapReqBuilder builder = new CapReqBuilder(namespace); JsonNode dirsNode = reqNode.get("dirs"); if (dirsNode != null) { if (dirsNode.isArray()) { for (JsonNode dirNode : dirsNode) { toDirective(builder, dirNode); }/*from ww w . j av a 2 s. c o m*/ } else if (dirsNode.isObject()) { toDirective(builder, dirsNode); } else { throw new IllegalAccessError("Value of 'dirs' node is neither an Array or an Object."); } } JsonNode attrsNode = reqNode.get("attrs"); if (attrsNode != null) { if (attrsNode.isArray()) { for (JsonNode attrNode : attrsNode) { toAttribute(builder, attrNode); } } else if (attrsNode.isObject()) { toAttribute(builder, attrsNode); } else { throw new IllegalAccessError("Value of 'attrs' node is neither an Array or an Object."); } } return builder; }
From source file:com.baasbox.service.scripting.ScriptingService.java
public static JsonNode callJsonSync(JsonNode req) throws Exception { JsonNode url = req.get("url"); JsonNode method = req.get("method"); JsonNode timeout = req.get("timeout"); if (url == null || url instanceof NullNode) throw new IllegalArgumentException("Missing URL to call"); if (method == null || method instanceof NullNode) throw new IllegalArgumentException("Missing method to use when calling the URL"); return callJsonSync(url.asText(), method.asText(), mapJson(req.get("params")), mapJson(req.get("headers")), req.get("body"), (timeout != null && timeout.isNumber()) ? timeout.asInt() : null); }
From source file:controllers.GoogleComputeEngineApplication.java
public static WebSocket<JsonNode> gceOperations() { return new WebSocket<JsonNode>() { public void onReady(final In<JsonNode> in, final Out<JsonNode> out) { final ActorRef computeActor = Akka.system() .actorOf(Props.create(GoogleComputeEngineConnection.class, out)); in.onMessage(new F.Callback<JsonNode>() { @Override//from w w w . j av a2 s . c om public void invoke(JsonNode jsonNode) throws Throwable { if (jsonNode.has("action") && "retrieve".equals(jsonNode.get("action").textValue())) { Date lastOperationDate = null; if (jsonNode.has("lastOperationDate")) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); try { lastOperationDate = format.parse(jsonNode.get("lastOperationDate").textValue()); } catch (ParseException e) { System.out.println("Date parse error: " + e.getMessage()); } } final ActorRef computeActor = Akka.system() .actorOf(Props.create(GoogleComputeEngineConnection.class, out)); GoogleComputeEngineService.listOperations(computeActor, lastOperationDate); } } }); in.onClose(new F.Callback0() { @Override public void invoke() throws Throwable { Akka.system().stop(computeActor); } }); } }; }
From source file:org.hbz.oerworldmap.NtToEs.java
static String findParent(String jsonLd) { ObjectMapper mapper = new ObjectMapper(); JsonNode value = null; try {//from w w w .ja v a2 s .co m value = mapper.readTree(jsonLd).findValue("addressCountry"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return value != null && value.isArray() /* else in context */ ? value.get(0).asText().trim() : "http://sws.geonames.org/"; }
From source file:com.squarespace.template.plugins.platform.CommerceUtils.java
public static void writeVariantFormat(JsonNode variant, StringBuilder buf) { ArrayNode optionValues = (ArrayNode) variant.get("optionValues"); if (optionValues == null) { return;/*from w w w . j a v a2s . co m*/ } Iterator<JsonNode> iterator = optionValues.elements(); List<String> values = new ArrayList<>(); while (iterator.hasNext()) { JsonNode option = iterator.next(); values.add(option.get("value").asText()); } int size = values.size(); for (int i = 0; i < size; i++) { if (i > 0) { buf.append(" / "); } buf.append(values.get(i)); } }
From source file:com.ikanow.aleph2.security.utils.LdifExportUtil.java
/** * Returns the sourceIds and the bucket IDs associated with the community. * @param communityId/*w w w .j a v a 2s . c o m*/ * @return * @throws ExecutionException * @throws InterruptedException protected Tuple2<Set<String>, Set<String>> loadSourcesAndBucketIdsByCommunityId(String communityId) throws InterruptedException, ExecutionException { Set<String> sourceIds = new HashSet<String>(); Set<String> bucketIds = new HashSet<String>(); ObjectId objecId = new ObjectId(communityId); Cursor<JsonNode> cursor = getSourceDb().getObjectsBySpec(CrudUtils.anyOf().when("communityIds", objecId)).get(); for (Iterator<JsonNode> it = cursor.iterator(); it.hasNext();) { JsonNode source = it.next(); String sourceId = source.get("_id").asText(); sourceIds.add(sourceId); JsonNode extracType = source.get("extractType"); if(extracType!=null && "V2DataBucket".equalsIgnoreCase(extracType.asText())){ JsonNode bucketId = source.get("key"); if(bucketId !=null){ // TODO HACK , according to Alex, buckets have a semicolon as last id character to facilitate some string conversion bucketIds.add(bucketId.asText()+";"); } } // bucket id } return new Tuple2<Set<String>, Set<String>>(sourceIds,bucketIds); } */ protected static String extractField(JsonNode node, String field) { String value = ""; if (node != null) { JsonNode fieldNode = node.get(field); if (fieldNode != null) { value = fieldNode.asText(); } } return value; }