JsonNode json = request().body().asJson(); for (JsonNode language : json.withArray("languages")) { Logger.info("language -> " + language.get("someField").asText()); //do something else }
public static ApiVersion read(final String json) throws IOException { final JsonNode actualObj = MAPPER.readTree(json); final String branch = actualObj.get("branch").asText(); final String commitId = actualObj.get("commitId").asText(); final String commitIdAbbrev = actualObj.get("commitIdAbbrev").asText(); final String buildVersion = actualObj.get("buildVersion").asText(); final OffsetDateTime buildTime = OffsetDateTime.parse(actualObj.get("buildTime").asText(), FORMATTER); final OffsetDateTime apiTime = OffsetDateTime.parse(actualObj.get("currentApiTime").asText()); // ISO8601 format final Iterable<JsonNode> n = actualObj.withArray("tags"); final String[] tags = StreamSupport.stream(n.spliterator(), false) .map(JsonNode::asText) .toArray(String[]::new); return new ApiVersion(branch, commitId, commitIdAbbrev, buildTime, buildVersion, apiTime, tags); }
private static List<String> getRequiredList(JsonNode jsonNode) { if (jsonNode.path(FIELD_REQUIRED).isMissingNode()) { return Collections.emptyList(); } Assert.isTrue(jsonNode.path(FIELD_REQUIRED).isArray(), "'required' property must have type: array"); List<String> requiredList = new ArrayList<>(); for (JsonNode requiredField : jsonNode.withArray(FIELD_REQUIRED)) { Assert.isTrue(requiredField.isTextual(), "required must be string"); requiredList.add(requiredField.asText()); } return requiredList; } }
private String extractLabels(JsonNode tree) { Iterator<JsonNode> it = tree.withArray("labels").iterator(); CollectionStringBuffer csb = new CollectionStringBuffer(","); while (it.hasNext()) { String text = it.next().textValue(); csb.append(text); } return csb.toString(); }
/** * Adds any discovered third party Camel connectors from the artifact. */ private void addCustomCamelConnectorFromArtifact(NexusArtifactDto dto, URL jarUrl) { try (URLClassLoader classLoader = new URLClassLoader(new URL[] {jarUrl});) { String[] json = loadConnectorJSonSchema(classLoader); if (json != null) { ObjectMapper mapper = new ObjectMapper(); JsonNode tree = mapper.readTree(json[0]); String name = tree.get("name").textValue(); String scheme = tree.get("scheme").textValue(); String javaType = tree.get("javaType").textValue(); String description = tree.get("description").textValue(); Iterator<JsonNode> it = tree.withArray("labels").iterator(); CollectionStringBuffer csb = new CollectionStringBuffer(","); while (it.hasNext()) { String text = it.next().textValue(); csb.append(text); } addConnector(dto, name, scheme, javaType, description, csb.toString(), json[0], json[1], json[2]); } } catch (IOException e) { logger.warn("Error scanning JAR for custom Camel connectors", e); } }
JsonNode graph = raw.withArray("@graph");
JsonNode graph = raw.withArray("@graph");
private List<ConfluenceAttachment> getNextAttachments(String contentId, int limit, int start) { List<ConfluenceAttachment> attachments = new ArrayList<>(limit); HttpGet getAttachmentsRequest = this.httpRequestFactory.getAttachmentsRequest(contentId, limit, start, "version"); return sendRequestAndFailIfNot20x(getAttachmentsRequest, (response) -> { JsonNode jsonNode = parseJsonResponse(response); jsonNode.withArray("results").forEach(attachment -> attachments.add(extractConfluenceAttachment(attachment))); return attachments; }); }
String javaType = tree.get("javaType").textValue(); String description = tree.get("description").textValue(); Iterator<JsonNode> it = tree.withArray("labels").iterator();
private List<ConfluencePage> getNextChildPages(String contentId, int limit, int start) { List<ConfluencePage> pages = new ArrayList<>(limit); HttpGet getChildPagesByIdRequest = this.httpRequestFactory.getChildPagesByIdRequest(contentId, limit, start, "version"); return sendRequestAndFailIfNot20x(getChildPagesByIdRequest, (response) -> { JsonNode jsonNode = parseJsonResponse(response); jsonNode.withArray("results").forEach((page) -> pages.add(extractConfluencePageWithoutContent(page))); return pages; }); }
@Override public String getPageByTitle(String spaceKey, String title) throws NotFoundException, MultipleResultsException { HttpGet pageByTitleRequest = this.httpRequestFactory.getPageByTitleRequest(spaceKey, title); return sendRequestAndFailIfNot20x(pageByTitleRequest, (response) -> { JsonNode jsonNode = parseJsonResponse(response); int numberOfResults = jsonNode.get("size").asInt(); if (numberOfResults == 0) { throw new NotFoundException(); } if (numberOfResults > 1) { throw new MultipleResultsException(); } String contentId = extractIdFromJsonNode(jsonNode.withArray("results").elements().next()); return contentId; }); }
@Override public ConfluenceAttachment getAttachmentByFileName(String contentId, String attachmentFileName) throws NotFoundException, MultipleResultsException { HttpGet attachmentByFileNameRequest = this.httpRequestFactory.getAttachmentByFileNameRequest(contentId, attachmentFileName, "version"); return sendRequestAndFailIfNot20x(attachmentByFileNameRequest, (response) -> { JsonNode jsonNode = parseJsonResponse(response); int numberOfResults = jsonNode.get("size").asInt(); if (numberOfResults == 0) { throw new NotFoundException(); } if (numberOfResults > 1) { throw new MultipleResultsException(); } ConfluenceAttachment attachmentId = extractConfluenceAttachment(jsonNode.withArray("results").elements().next()); return attachmentId; }); }