List of usage examples for com.fasterxml.jackson.databind JsonNode textValue
public String textValue()
From source file:org.apache.kylin.tool.MrJobInfoExtractor.java
private void extractTaskDetail(String taskId, String user, File exportDir, String taskUrl, String urlBase) throws IOException { try {// ww w . j a va2 s . c om if (StringUtils.isEmpty(taskId)) { return; } String taskUrlBase = taskUrl + taskId; File destDir = new File(exportDir, taskId); // get task basic info String taskInfo = saveHttpResponseQuietly(new File(destDir, "task.json"), taskUrlBase); JsonNode taskAttempt = new ObjectMapper().readTree(taskInfo).path("task").path("successfulAttempt"); String succAttemptId = taskAttempt.textValue(); String attemptInfo = saveHttpResponseQuietly(new File(destDir, "task_attempts.json"), taskUrlBase + "/attempts/" + succAttemptId); JsonNode attemptAttempt = new ObjectMapper().readTree(attemptInfo).path("taskAttempt"); String containerId = attemptAttempt.get("assignedContainerId").textValue(); String nodeId = nodeInfoMap.get(attemptAttempt.get("nodeHttpAddress").textValue()); // save task counters saveHttpResponseQuietly(new File(destDir, "task_counters.json"), taskUrlBase + "/counters"); // save task logs String logUrl = urlBase + "/jobhistory/logs/" + nodeId + "/" + containerId + "/" + succAttemptId + "/" + user + "/syslog/?start=0"; logger.debug("Fetch task log from url: " + logUrl); saveHttpResponseQuietly(new File(destDir, "task_log.txt"), logUrl); } catch (Exception e) { logger.warn("Failed to get task counters rest response" + e); } }
From source file:com.github.restdriver.matchers.HasJsonValue.java
@Override public boolean matchesSafely(JsonNode jsonNode) { JsonNode node = jsonNode.get(fieldName); if (node == null) { return false; }//from w w w . j a v a 2s .co m if (node.isInt()) { return valueMatcher.matches(node.intValue()); } else if (node.isLong()) { return valueMatcher.matches(node.longValue()); } else if (node.isTextual()) { return valueMatcher.matches(node.textValue()); } else if (node.isBoolean()) { return valueMatcher.matches(node.booleanValue()); } else if (node.isDouble()) { return valueMatcher.matches(node.doubleValue()); } else if (node.isObject()) { return valueMatcher.matches(node); } else if (node.isNull()) { return valueMatcher.matches(null); } else { return false; } }
From source file:com.github.fge.jsonschema.core.report.ProcessingMessage.java
@Override public String toString() { final Map<String, JsonNode> tmp = Maps.newLinkedHashMap(map); final JsonNode node = tmp.remove("message"); final String message = node == null ? "(no message)" : node.textValue(); final StringBuilder sb = new StringBuilder().append(level).append(": "); sb.append(message);/*from w w w .ja v a 2 s. co m*/ for (final Map.Entry<String, JsonNode> entry : tmp.entrySet()) sb.append("\n ").append(entry.getKey()).append(": ").append(entry.getValue()); return sb.append('\n').toString(); }
From source file:org.eel.kitchen.jsonschema.format.EmailFormatAttribute.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode instance) { // Yup, that is kind of misnamed. But the problem is with the // InternetAddress constructor in the first place which "enforces" a // syntax which IS NOT strictly RFC compliant. final boolean strictRFC = ctx.hasFeature(ValidationFeature.STRICT_RFC_CONFORMANCE); try {/*from w w w . j ava 2s. c o m*/ // Which means we actually invert it. new InternetAddress(instance.textValue(), !strictRFC); } catch (AddressException ignored) { final Message.Builder msg = newMsg(fmt).setMessage("string is not a valid email address") .addInfo("value", instance); report.addMessage(msg.build()); } }
From source file:com.ottogroup.bi.asap.operator.json.aggregator.JsonContentAggregator.java
/** * Walks along the path provided and reads out the leaf value which is returned as string * @param jsonNode/*from w w w . j a v a2 s. c om*/ * @param fieldPath * @return */ protected String getTextFieldValue(final JsonNode jsonNode, final String[] fieldPath) { int fieldAccessStep = 0; JsonNode contentNode = jsonNode; while (fieldAccessStep < fieldPath.length) { contentNode = contentNode.get(fieldPath[fieldAccessStep]); fieldAccessStep++; } return contentNode.textValue(); }
From source file:com.amazonaws.services.iot.client.shadow.AwsIotDeviceCommandManager.java
private AwsIotDeviceCommand getPendingCommand(AWSIotMessage message) { String payload = message.getStringPayload(); if (payload == null) { return null; }//from ww w .j a v a 2 s . com try { JsonNode jsonNode = objectMapper.readTree(payload); if (!jsonNode.isObject()) { return null; } JsonNode node = jsonNode.get(COMMAND_ID_FIELD); if (node == null) { return null; } String commandId = node.textValue(); AwsIotDeviceCommand command = pendingCommands.remove(commandId); if (command == null) { return null; } node = jsonNode.get(ERROR_CODE_FIELD); if (node != null) { command.setErrorCode(AWSIotDeviceErrorCode.valueOf(node.longValue())); } node = jsonNode.get(ERROR_MESSAGE_FIELD); if (node != null) { command.setErrorMessage(node.textValue()); } return command; } catch (IOException e) { return null; } }
From source file:org.level28.android.moca.json.FaqDeserializer.java
@Override public List<FaqEntry> fromInputStream(InputStream in) throws JsonDeserializerException { JsonNode root;//from w w w . j a v a 2 s . c o m try { root = sJsonMapper.readTree(in); } catch (IOException e) { throw new JsonDeserializerException("Internal Jackson error", e); } if (!root.isArray()) { throw new JsonDeserializerException("Root node is not an array"); } // I miss list comprehensions :-( ArrayList<FaqEntry> result = Lists.newArrayList(); for (JsonNode node : root) { if (node == null || node.isNull()) { throw new JsonDeserializerException("null objectRoot"); } if (!node.isObject()) { throw new JsonDeserializerException("objectRoot is not a JSON object"); } final JsonNode categoryName = node.path("category"); final JsonNode entries = node.path("faqs"); if (categoryName.isMissingNode() || entries.isMissingNode() || !categoryName.isTextual() || !entries.isArray()) { throw new JsonDeserializerException("Malformed FAQ category"); } final String category = categoryName.textValue(); for (JsonNode childNode : entries) { result.add(parseEntry(category, childNode)); } } return result; }
From source file:com.almende.eve.capabilities.Config.java
/** * Setup extends./*from w w w. ja v a 2 s . co m*/ */ public void setupExtend() { configured = true; final JsonNode extNode = this.get("extends"); if (extNode == null || extNode.isNull()) { return; } ObjectNode reference = null; boolean found = false; final String path = extNode.textValue(); if (path != null && !path.equals("")) { reference = (ObjectNode) this.lget(path.split("/")); if (reference == null || reference.isNull()) { reference = (ObjectNode) global.lget(path.split("/")); found = true; } } if (reference != null && !reference.isNull()) { Config refConf = null; if (reference instanceof Config) { refConf = (Config) reference; } else { refConf = new Config((ObjectNode) reference); } if (!found) { String ref = new UUID().toString(); global.set(ref, refConf); } getPointers().add(refConf); } }
From source file:com.buession.oauth.provider.impl.QqProvider.java
/** * Retrieve the user profile from the access token. * // www .j a va 2 s . co m * @param accessToken * @return the user profile object * @throws HttpException */ @Override protected UserProfile retrieveUserProfile(final Token accessToken) throws HttpException { String openIdUrl = getOpenIdUrl(); logger.debug("get openid from: " + openIdUrl); String body = sendRequestForData(accessToken, openIdUrl); if (body == null) { return null; } String str = body.replace("callback( ", "").replace(" );", ""); JsonNode json = JsonHelper.getFirstNode(str); JsonNode clientid = json.get("client_id"); JsonNode openid = json.get("openid"); if (openid == null) { throw new OAuthException("Response body is incorrect. Can't extract a openid from this: '" + body + "'", null); } String url = getProfileUrl() + "?oauth_consumer_key=" + clientid.textValue() + "&openid=" + openid.textValue(); logger.debug("get user profile by clientid<" + clientid + "> and openid<" + openid + "> from: " + url); body = sendRequestForData(accessToken, url); final UserProfile profile = extractUserProfile(body); profile.setId(openid.textValue()); addAccessTokenToProfile(profile, accessToken); return profile; }
From source file:com.github.pjungermann.config.types.json.JsonConverter.java
@Nullable protected Object extractValue(@NotNull final JsonNode node) { if (node.isNull()) { return null; }// w w w .j a v a2s . com if (node.isBoolean()) { return node.booleanValue(); } if (node.isNumber()) { return node.numberValue(); } if (node.isTextual()) { return node.textValue(); } if (node.isBinary()) { try { return node.binaryValue(); } catch (IOException e) { LOGGER.error( String.format("failed to read binary value from node %s of type %s", node, node.getClass()), e); } } if (node instanceof ArrayNode) { return prepareEntries((ArrayNode) node); } throw new UnsupportedOperationException( String.format("node %s of type %s is not supported", node, node.getClass())); }