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

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

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

JsonNode.forEach介绍

暂无

代码示例

代码示例来源:origin: line/armeria

private static void removeDocStrings(JsonNode json) {
  if (json.isObject()) {
    ((ObjectNode) json).remove("docString");
  }
  if (json.isObject() || json.isArray()) {
    json.forEach(GrpcDocServiceTest::removeDocStrings);
  }
}

代码示例来源:origin: line/armeria

private static void addExamples(JsonNode json) {
  json.get("services").forEach(service -> {
    final String serviceName = service.get("name").textValue();
    // Add the method-specific examples.
    service.get("methods").forEach(method -> {
      final String methodName = method.get("name").textValue();
      final ArrayNode exampleRequests = (ArrayNode) method.get("exampleRequests");
      if (TestServiceGrpc.SERVICE_NAME.equals(serviceName) &&
        "UnaryCall".equals(methodName)) {
        exampleRequests.add("{\n" +
                  "  \"payload\": {\n" +
                  "    \"body\": \"d29ybGQ=\"\n" +
                  "  }\n" +
                  '}');
      }
    });
  });
}

代码示例来源:origin: line/armeria

private static void removeDocStrings(JsonNode json) {
  if (json.isObject()) {
    ((ObjectNode) json).remove("docString");
  }
  if (json.isObject() || json.isArray()) {
    json.forEach(ThriftDocServiceTest::removeDocStrings);
  }
}

代码示例来源:origin: line/armeria

json.get("services").forEach(service -> {
  service.get("methods").forEach(method -> {
    final String methodName = method.get("name").textValue();
    final ArrayNode exampleHttpHeaders = (ArrayNode) method.get("exampleHttpHeaders");

代码示例来源:origin: net.nemerosa/resources-json

public static List<String> getStringList(JsonNode data, String field) {
  if (data.has(field)) {
    List<String> list = new ArrayList<>();
    data.get(field).forEach(node -> list.add(node.asText()));
    return list;
  } else {
    return null;
  }
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-json

public static List<String> getStringList(JsonNode data, String field) {
  if (data.has(field)) {
    List<String> list = new ArrayList<>();
    data.get(field).forEach(node -> list.add(node.asText()));
    return list;
  } else {
    return null;
  }
}

代码示例来源:origin: RepreZen/KaiZen-OpenAPI-Editor

protected String rewriteRequiredProperties(JsonNode error) {
  JsonNode missing = error.get("missing");
  
  final StringJoiner missingStringJoiner = new StringJoiner(", ");
  missing.forEach(it -> missingStringJoiner.add(it.toString()));
  return String.format(Messages.error_missing_property, missingStringJoiner.toString());
}

代码示例来源:origin: RepreZen/KaiZen-OpenAPI-Editor

protected String rewriteAdditionalProperties(JsonNode error) {
  final JsonNode unwanted = error.get("unwanted");
  final StringJoiner unwantedStringJoiner = new StringJoiner(", ");
  unwanted.forEach(it -> unwantedStringJoiner.add(it.toString()));
  return String.format(Messages.error_additional_properties_not_allowed, unwantedStringJoiner.toString());
}

代码示例来源:origin: ORCID/ORCID-Source

private void processDeletedElements(JsonNode deletedIds) {
  LOGGER.info("Processing deleted elements");
  deletedIds.forEach(element -> {
    Integer oldId = element.has("old_ringgold_id") ? element.get("old_ringgold_id").asInt() : null;
    Integer newId = element.has("new_ringgold_id") ? element.get("new_ringgold_id").asInt() : null;
    deletedElementsMap.put(oldId, newId);
  });
}

代码示例来源:origin: RepreZen/KaiZen-OpenAPI-Editor

protected String rewriteEnumError(JsonNode error) {
  final JsonNode value = error.get("value");
  final JsonNode enums = error.get("enum");
  final StringJoiner enumStringJoiner = new StringJoiner(", ");
  enums.forEach(it -> enumStringJoiner.add(it.toString()));
  return String.format(Messages.error_notInEnum, value.asText(), enumStringJoiner.toString());
}

代码示例来源:origin: excelsior-oss/restler

private HashMap<String, String> getObjectHrefs(JsonNode objectNode) {
  HashMap<String, String> result = new LinkedHashMap<>();
  JsonNode linksNode = objectNode.get("_links");
  Iterator<String> names = linksNode.fieldNames();
  linksNode.forEach(node ->
      result.put(names.next(), node.get("href").toString().replace("\"", "")));
  return result;
}

代码示例来源:origin: ORCID/ORCID-Source

private void processIdentifiers(JsonNode identifiers) {
  LOGGER.info("Processing identifiers");
  identifiers.forEach(identifier -> {
    Integer ringgoldId = identifier.get("ringgold_id").asInt();
    String identifierType = identifier.get("identifier_type").asText();
    if(ALLOWED_EXTERNAL_IDENTIFIERS.contains(identifierType)) {
      identifiersMap.computeIfAbsent(ringgoldId, element -> new ArrayList<>()).add(identifier);
    } else {
      LOGGER.info("Ignoring identifier {} of type {}", ringgoldId, identifierType);
    }
  });
}

代码示例来源:origin: LendingClub/mercator

public KubeScannerBuilder withKubeConfigUser(String user) {
  kubeConfig.path("users").forEach(it -> {
    if (it.path("name").asText().equals(user)) {
      String authToken = it.path("user").path("auth-provider").path("config").path("access-token").asText();
      withConfig(c -> {
        logger.info("setting token");
        c.withOauthToken(authToken);
      });
    }
  });
  return this;
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-extension-artifactory

@Override
public List<String> getBuildNames() {
  JsonNode node = jsonClient.get("/api/build");
  List<String> names = new ArrayList<>();
  node.path("builds").forEach((JsonNode numberNode) -> {
    String name = StringUtils.stripStart(numberNode.path("uri").asText(), "/");
    if (StringUtils.isNotBlank(name)) {
      names.add(name);
    }
  });
  return names;
}

代码示例来源:origin: com.sonymobile/lumbermill-core

public Observable<JsonEvent> each() {
  List<JsonEvent> list = new ArrayList<>();
  if (objectNodeOrArrayNode instanceof ObjectNode) {
    return Observable.from(asList(new JsonEvent((ObjectNode) objectNodeOrArrayNode)));
  }
  objectNodeOrArrayNode.forEach(node -> list.add(new JsonEvent((ObjectNode) node)));
  return Observable.from(list);
}

代码示例来源:origin: HuygensING/timbuctoo

private void throwIfInvalid(JsonNode json) throws IOException {
 if (json instanceof ArrayNode) {
  json.forEach(rethrowConsumer(val -> {
   try {
    StringToEncodedStringOfLimitedValuesConverter.throwIfInvalid(val, this.allowedValues);
   } catch (IOException e) {
    throw new IOException(val + e.getMessage(), e);
   }
  }));
 } else {
  throw new IOException("should be an array.");
 }
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-extension-general

private List<ValidationStamp> readValidationStamps(JsonNode validationStampIds) {
  List<ValidationStamp> validationStampList;
  if (validationStampIds.isArray()) {
    List<Integer> ids = new ArrayList<>();
    validationStampIds.forEach(id -> ids.add(id.asInt()));
    // Reading the validation stamps and then the names
    validationStampList = ids.stream()
        .map(id -> structureService.getValidationStamp(ID.of(id)))
        .collect(Collectors.toList());
  } else {
    throw new AutoPromotionPropertyCannotParseException("Cannot get the list of validation stamps");
  }
  return validationStampList;
}

代码示例来源:origin: org.onosproject/onos-app-xos-client

@Override
public Set<VtnServiceId> providerServices(VtnServiceId tServiceId) {
  checkNotNull(tServiceId);
  String response = restGet(tServiceId.id());
  log.trace("Get provider services {}", response);
  ObjectMapper mapper = new ObjectMapper();
  Set<VtnServiceId> pServices = Sets.newHashSet();
  try {
    JsonNode nodes = mapper.readTree(response);
    nodes.forEach(node -> pServices.add(VtnServiceId.of(node.asText())));
  } catch (IOException e) {
    log.warn("Failed to get service dependency");
  }
  return pServices;
}

代码示例来源: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: 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;
  });
}

相关文章