Java Code Examples for com.fasterxml.jackson.databind.JsonNode#findParents()

The following examples show how to use com.fasterxml.jackson.databind.JsonNode#findParents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProductBatchProcessor.java    From commercetools-sync-java with Apache License 2.0 6 votes vote down vote up
/**
 * Get a set of referenced product keys given an attribute draft.
 *
 * @param attributeDraft the attribute to get the referenced keys from.
 * @return set of referenced product keys given an attribute draft.
 */
@Nonnull
private static Set<String> getReferencedProductKeys(@Nonnull final AttributeDraft attributeDraft) {

    final JsonNode attributeDraftValue = attributeDraft.getValue();
    if (attributeDraftValue == null) {
        return emptySet();
    }

    final List<JsonNode> allAttributeReferences = attributeDraftValue.findParents(REFERENCE_TYPE_ID_FIELD);

    return allAttributeReferences
        .stream()
        .filter(reference -> isReferenceOfType(reference, Product.referenceTypeId()))
        .map(reference -> reference.get(REFERENCE_ID_FIELD).asText())
        .filter(Objects::nonNull)
        .collect(Collectors.toSet());
}
 
Example 2
Source File: VariantReferenceResolver.java    From commercetools-sync-java with Apache License 2.0 6 votes vote down vote up
@Nonnull
private CompletionStage<AttributeDraft> resolveAttributeReference(@Nonnull final AttributeDraft attributeDraft) {

    final JsonNode attributeDraftValue = attributeDraft.getValue();

    if (attributeDraftValue == null) {
        return CompletableFuture.completedFuture(attributeDraft);
    }

    final JsonNode attributeDraftValueClone = attributeDraftValue.deepCopy();

    final List<JsonNode> allAttributeReferences = attributeDraftValueClone.findParents(REFERENCE_TYPE_ID_FIELD);

    if (!allAttributeReferences.isEmpty()) {
        return mapValuesToFutureOfCompletedValues(allAttributeReferences, this::resolveReference, toList())
            .thenApply(ignoredResult -> AttributeDraft.of(attributeDraft.getName(), attributeDraftValueClone));
    }

    return CompletableFuture.completedFuture(attributeDraft);
}
 
Example 3
Source File: ArrayNode.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
{
    for (JsonNode node : _children) {
        foundSoFar = node.findParents(fieldName, foundSoFar);
    }
    return foundSoFar;
}
 
Example 4
Source File: CreateSchema.java    From bender with Apache License 2.0 5 votes vote down vote up
private static void modifyNode(JsonNode schema) {
  List<JsonNode> parents = schema.findParents("items");

  for (JsonNode parent : parents) {
    if (parent.hasNonNull("type") && parent.get("type").asText().equals("array")) {
      if (parent.get("items").hasNonNull("oneOf")) {
        ((ObjectNode) parent).put("anyOf", parent.get("items").get("oneOf"));
        ((ObjectNode) parent).remove("items");
      }
    }
  }
}