List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:com.nirmata.workflow.details.JsonSerializer.java
public static TaskExecutionResult getTaskExecutionResult(JsonNode node) { JsonNode subTaskRunIdNode = node.get("subTaskRunId"); return new TaskExecutionResult(TaskExecutionStatus.valueOf(node.get("status").asText().toUpperCase()), node.get("message").asText(), getMap(node.get("resultData")), ((subTaskRunIdNode != null) && !subTaskRunIdNode.isNull()) ? new RunId(subTaskRunIdNode.asText()) : null,//from ww w . ja v a2 s . c om LocalDateTime.parse(node.get("completionTimeUtc").asText(), DateTimeFormatter.ISO_DATE_TIME)); }
From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java
public static InputStream getJsonProperty(final InputStream src, final String[] path, final String edmType) throws Exception { final ObjectMapper mapper = new ObjectMapper(); final JsonNode srcNode = mapper.readTree(src); final ObjectNode property = new ObjectNode(JsonNodeFactory.instance); if (StringUtils.isNotBlank(edmType)) { property.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + edmType); }//from w w w.j a v a2 s . c o m JsonNode jsonNode = getJsonProperty(srcNode, path, 0); if (jsonNode.isObject()) { property.putAll((ObjectNode) jsonNode); } else { property.put("value", jsonNode.asText()); } final ByteArrayOutputStream bos = new ByteArrayOutputStream(); mapper.writeValue(bos, property); final InputStream res = new ByteArrayInputStream(bos.toByteArray()); IOUtils.closeQuietly(bos); return res; }
From source file:com.baasbox.service.scripting.ScriptingService.java
public static ScriptStatus update(String name, JsonNode code) throws ScriptException { if (code == null) throw new ScriptException("missing code"); JsonNode codeNode = code.get(ScriptsDao.CODE); if (codeNode == null || !codeNode.isTextual()) { throw new ScriptException("missing code"); }/*from ww w . j a va 2 s.c o m*/ String source = codeNode.asText(); return update(name, source); }
From source file:gate.corpora.twitter.TweetUtils.java
public static Object process(JsonNode node) { /* JSON types: number, string, boolean, array, object (dict/map), * null. All map keys are strings./*from w ww .ja v a2 s . c o m*/ */ if (node.isBoolean()) { return node.asBoolean(); } if (node.isDouble()) { return node.asDouble(); } if (node.isInt()) { return node.asInt(); } if (node.isTextual()) { return node.asText(); } if (node.isNull()) { return null; } if (node.isArray()) { List<Object> list = new ArrayList<Object>(); for (JsonNode item : node) { list.add(process(item)); } return list; } if (node.isObject()) { FeatureMap map = Factory.newFeatureMap(); Iterator<String> keys = node.fieldNames(); while (keys.hasNext()) { String key = keys.next(); map.put(key, process(node.get(key))); } return map; } return node.toString(); }
From source file:org.fcrepo.camel.processor.EventProcessor.java
private static Optional<List<String>> getValues(final JsonNode node, final String fieldName) { if (node.has(fieldName)) { final JsonNode field = node.get(fieldName); if (field.isArray()) { final List<String> elements = new ArrayList<>(); field.elements().forEachRemaining(elem -> { if (elem.isTextual()) { elements.add(elem.asText()); }/*from w w w.j a v a 2 s .c om*/ }); return of(elements); } else if (field.isTextual()) { return of(singletonList(field.asText())); } } return empty(); }
From source file:com.redhat.lightblue.mongo.config.MongoConfiguration.java
public static MongoCredential credentialFromJson(ObjectNode node) { String userName = null;/*from ww w .j ava2 s . c o m*/ String password = null; String source = null; JsonNode xnode = node.get("mechanism"); if (xnode == null) { throw new IllegalArgumentException("mechanism is required in credentials"); } String mech = xnode.asText(); xnode = node.get("userName"); if (xnode != null) { userName = xnode.asText(); } xnode = node.get("password"); if (xnode != null) { password = xnode.asText(); } xnode = node.get("source"); if (xnode != null) { source = xnode.asText(); } MongoCredential cr = null; if (null != mech) { switch (mech) { case "GSSAPI_MECHANISM": cr = MongoCredential.createGSSAPICredential(userName); break; case "MONGODB_CR_MECHANISM": cr = MongoCredential.createMongoCRCredential(userName, source, password == null ? null : password.toCharArray()); break; case "MONGODB_X509_MECHANISM": cr = MongoCredential.createMongoX509Credential(userName); break; case "PLAIN_MECHANISM": cr = MongoCredential.createPlainCredential(userName, source, password == null ? null : password.toCharArray()); break; default: throw new IllegalArgumentException("invalid mechanism:" + mech + ", must be one of " + "GSSAPI_MECHANISM, MONGODB_CR_MECHANISM, " + "MONGODB_X5090_MECHANISM, or PLAIN_MECHANISM"); } } return cr; }
From source file:com.bbva.kltt.apirest.core.util.parser.ParserUtil.java
/** * @param nodeName with the node name/*w w w.ja v a2 s. com*/ * @param node with the node to search the field * @param fieldName with the field name to be searched * @param isRequired true if the field is required * @return the field value as set * @throws APIRestGeneratorException with an occurred exception */ public static Set<String> getNodeValueSetField(final String nodeName, final JsonNode node, final String fieldName, final boolean isRequired) throws APIRestGeneratorException { Set<String> outcome = null; final boolean hasField = node.has(fieldName); if (hasField) { JsonNode jsonNode = node.get(fieldName); if (jsonNode instanceof ArrayNode) { outcome = ParserUtil.generateSetStringFromString((ArrayNode) jsonNode); } else { outcome = new HashSet<String>(); if (!jsonNode.isNull()) { outcome.add(jsonNode.asText()); } } } else if (!hasField && isRequired) { ParserUtil.generateExceptionRequiredField(nodeName, fieldName); } return outcome; }
From source file:io.gravitee.policy.oauth2.Oauth2Policy.java
static boolean hasRequiredScopes(JsonNode oauthResponseNode, List<String> requiredScopes, String scopeSeparator) {/* w w w. ja v a 2s . c om*/ if (requiredScopes == null) { return true; } JsonNode scopesNode = oauthResponseNode.path(OAUTH_PAYLOAD_SCOPE_NODE); List<String> scopes; if (scopesNode instanceof ArrayNode) { Iterator<JsonNode> scopeIterator = scopesNode.elements(); scopes = new ArrayList<>(scopesNode.size()); List<String> finalScopes = scopes; scopeIterator.forEachRemaining(jsonNode -> finalScopes.add(jsonNode.asText())); } else { scopes = Arrays.asList(scopesNode.asText().split(scopeSeparator)); } return scopes.containsAll(requiredScopes); }
From source file:com.tda.sitefilm.allocine.JSONAllocineAPIHelper.java
private static String getValueAsString(JsonNode node) { if (node == null) { return null; } else if (node.isNull()) { return null; }/*from w w w . jav a 2 s .c o m*/ return String.valueOf(node.asText()); }
From source file:controllers.nwbib.Lobid.java
/** * @param itemUri The lobid item URI//from w ww . j a v a2s.co m * @return The OPAC URL for the given item, or null */ public static String opacUrl(String itemUri) { try (InputStream stream = Play.application().resourceAsStream("isil2opac_hbzid.json")) { JsonNode json = Json.parse(stream); String[] hbzId_isil_sig = itemUri.substring(itemUri.indexOf("item/") + 5).split(":"); String hbzId = hbzId_isil_sig[0]; String isil = hbzId_isil_sig[1]; Logger.debug("From item URI {}, got ISIL {} and HBZ-ID {}", itemUri, isil, hbzId); JsonNode urlTemplate = json.get(isil); if (urlTemplate != null) return urlTemplate.asText().replace("{hbzid}", hbzId); } catch (IOException e) { Logger.error("Could not create OPAC URL", e); } return null; }