com.fasterxml.jackson.databind.JsonNode.withArray()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中com.fasterxml.jackson.databind.JsonNode.withArray()方法的一些代码示例,展示了JsonNode.withArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.withArray()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:withArray

JsonNode.withArray介绍

[英]Method that can be called on Object nodes, to access a property that has Array value; or if no such property exists, to create, add and return such Array node. If the node method is called on is not Object node, or if property exists and has value that is not Array node, UnsupportedOperationException is thrown
[中]方法,以访问具有Array值的属性;或者,如果不存在这样的属性,则创建、添加并返回这样的数组节点。如果调用的节点方法不是对象节点,或者如果属性存在并且其值不是数组节点,则会引发UnsupportdOperationException

代码示例

代码示例来源:origin: stackoverflow.com

JsonNode json = request().body().asJson();

for (JsonNode language : json.withArray("languages")) {
  Logger.info("language -> " + language.get("someField").asText());
  //do something else
}

代码示例来源:origin: com.github.robozonky/robozonky-app

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);
}

代码示例来源:origin: ethlo/jsons2xsd

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;
  }
}

代码示例来源:origin: io.syndesis/connector-catalog

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();
}

代码示例来源:origin: org.apache.camel/camel-catalog-nexus

/**
 * 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);
  }
}

代码示例来源:origin: org.dataconservancy.pass/pass-data-client

JsonNode graph = raw.withArray("@graph");

代码示例来源:origin: org.dataconservancy.pass/pass-client-shaded-v2_3

JsonNode graph = raw.withArray("@graph");

代码示例来源:origin: alainsahli/confluence-publisher

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;
  });
}

代码示例来源:origin: org.apache.camel/camel-catalog-maven

String javaType = tree.get("javaType").textValue();
String description = tree.get("description").textValue();
Iterator<JsonNode> it = tree.withArray("labels").iterator();

代码示例来源:origin: alainsahli/confluence-publisher

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;
  });
}

代码示例来源:origin: alainsahli/confluence-publisher

@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;
  });
}

代码示例来源:origin: alainsahli/confluence-publisher

@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;
  });
}

代码示例来源:origin: marklogic/marklogic-data-hub

((ArrayNode) rootNode.withArray("role")).insert(0, new TextNode("harmonized-reader"));
((ArrayNode) rootNode.withArray("role")).insert(0, new TextNode("harmonized-updater"));
((ArrayNode) rootNode.with("definitions").with("Customer").withArray("pii")).insert(
  0,
  new TextNode("ssn"));

代码示例来源:origin: marklogic/java-client-api

assertEquals("Format in the search handle", "json", results.get().withArray("results").get(1).path("format").asText());
assertTrue("Uri in search handle contains Artifact", results.get().withArray("results").get(1).path("uri").asText().contains("Artifact"));

代码示例来源:origin: marklogic/java-client-api

assertEquals("Format in the search handle", "json", results.get().withArray("results").get(1).path("format").asText());
assertTrue("Uri in search handle contains Artifact", results.get().withArray("results").get(1).path("uri").asText().contains("Artifact"));

相关文章