com.fasterxml.jackson.databind.node.ArrayNode.addAll()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(126)

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

ArrayNode.addAll介绍

[英]Method for adding all child nodes of given Array, appending to child nodes this array contains
[中]方法,用于添加给定数组的所有子节点,并附加到此数组包含的子节点

代码示例

代码示例来源:origin: java-json-tools/json-schema-validator

@Override
public JsonNode digest(final JsonNode schema)
{
  final SortedSet<JsonNode> set = Sets.newTreeSet(COMPARATOR);
  for (final JsonNode element: schema.get(keyword))
    set.add(element);
  return FACTORY.arrayNode().addAll(set);
}

代码示例来源:origin: java-json-tools/json-schema-validator

private static JsonNode sortedSet(final JsonNode node)
  {
    final List<JsonNode> list = Lists.newArrayList(node);

    Collections.sort(list, new Comparator<JsonNode>()
    {
      @Override
      public int compare(final JsonNode o1, final JsonNode o2)
      {
        return o1.textValue().compareTo(o2.textValue());
      }
    });

    final ArrayNode ret = FACTORY.arrayNode();
    ret.addAll(list);
    return ret;
  }
}

代码示例来源:origin: java-json-tools/json-schema-validator

private static JsonNode sortedSet(final JsonNode node)
  {
    final SortedSet<JsonNode> set
      = Sets.newTreeSet(new Comparator<JsonNode>()
      {
        @Override
        public int compare(final JsonNode o1, final JsonNode o2)
        {
          return o1.textValue().compareTo(o2.textValue());
        }
      });

    set.addAll(Sets.newHashSet(node));
    final ArrayNode ret = FACTORY.arrayNode();
    ret.addAll(set);
    return ret;
  }
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

private ObjectNode mergeObjectNodes(ObjectNode targetNode, ObjectNode updateNode) {
  Iterator<String> fieldNames = updateNode.fieldNames();
  while (fieldNames.hasNext()) {
    String fieldName = fieldNames.next();
    JsonNode targetValue = targetNode.get(fieldName);
    JsonNode updateValue = updateNode.get(fieldName);
    if (targetValue == null) {
      // Target node doesn't have this field from update node: just add it
      targetNode.set(fieldName, updateValue);
    } else {
      // Both nodes have the same field: merge the values
      if (targetValue.isObject() && updateValue.isObject()) {
        // Both values are objects: recurse
        targetNode.set(fieldName, mergeObjectNodes((ObjectNode) targetValue, (ObjectNode) updateValue));
      } else if (targetValue.isArray() && updateValue.isArray()) {
        // Both values are arrays: concatenate them to be merged later
        ((ArrayNode) targetValue).addAll((ArrayNode) updateValue);
      } else {
        // Values have different types: use the one from the update node
        targetNode.set(fieldName, updateValue);
      }
    }
  }
  return targetNode;
}

代码示例来源:origin: java-json-tools/json-schema-validator

@Override
  public JsonNode digest(final JsonNode schema)
  {
    final ObjectNode ret = FACTORY.objectNode();
    final ArrayNode required = FACTORY.arrayNode();
    ret.put(keyword, required);

    final List<JsonNode> list = Lists.newArrayList(schema.get(keyword));

    Collections.sort(list, new Comparator<JsonNode>()
    {
      @Override
      public int compare(final JsonNode o1, final JsonNode o2)
      {
        return o1.textValue().compareTo(o2.textValue());
      }
    });

    required.addAll(list);
    return ret;
  }
}

代码示例来源:origin: spring-io/initializr

protected void type(ObjectNode parent, TypeCapability capability) {
  ObjectNode type = nodeFactory.objectNode();
  type.put("type", "action");
  Type defaultType = capability.getDefault();
  if (defaultType != null) {
    type.put("default", defaultType.getId());
  }
  ArrayNode values = nodeFactory.arrayNode();
  values.addAll(capability.getContent().stream().map(this::mapType)
      .collect(Collectors.toList()));
  type.set("values", values);
  parent.set("type", type);
}

代码示例来源:origin: spring-io/initializr

protected void dependencies(ObjectNode parent, DependenciesCapability capability) {
  ObjectNode dependencies = nodeFactory.objectNode();
  dependencies.put("type", capability.getType().getName());
  ArrayNode values = nodeFactory.arrayNode();
  values.addAll(capability.getContent().stream().map(this::mapDependencyGroup)
      .collect(Collectors.toList()));
  dependencies.set("values", values);
  parent.set(capability.getId(), dependencies);
}

代码示例来源:origin: spring-io/initializr

protected void singleSelect(ObjectNode parent, SingleSelectCapability capability) {
  ObjectNode single = nodeFactory.objectNode();
  single.put("type", capability.getType().getName());
  DefaultMetadataElement defaultType = capability.getDefault();
  if (defaultType != null) {
    single.put("default", defaultType.getId());
  }
  ArrayNode values = nodeFactory.arrayNode();
  values.addAll(capability.getContent().stream().map(this::mapValue)
      .collect(Collectors.toList()));
  single.set("values", values);
  parent.set(capability.getId(), single);
}

代码示例来源:origin: graphhopper/graphhopper

requestJson.putArray("points").addAll(createPointList(ghRequest.getFromPoints()));
  requestJson.putArray("point_hints").addAll(createStringList(ghRequest.getFromPointHints()));
} else {
  ArrayNode fromPointList = createPointList(ghRequest.getFromPoints());
  ArrayNode toPointList = createPointList(ghRequest.getToPoints());
  requestJson.putArray("from_points").addAll(fromPointList);
  requestJson.putArray("from_point_hints").addAll(createStringList(ghRequest.getFromPointHints()));
  requestJson.putArray("to_points").addAll(toPointList);
  requestJson.putArray("to_point_hints").addAll(createStringList(ghRequest.getToPointHints()));
requestJson.putArray("out_arrays").addAll(outArrayListJson);
requestJson.put("vehicle", ghRequest.getVehicle());
requestJson.put("elevation", hasElevation);

代码示例来源:origin: HubSpot/Singularity

private static void merge(ObjectNode to, ObjectNode from) {
    Iterator<String> newFieldNames = from.fieldNames();

    while (newFieldNames.hasNext()) {
      String newFieldName = newFieldNames.next();
      JsonNode oldVal = to.get(newFieldName);
      JsonNode newVal = from.get(newFieldName);

      if (oldVal == null || oldVal.isNull()) {
        to.set(newFieldName, newVal);
      } else if (oldVal.isArray() && newVal.isArray()) {
        ((ArrayNode) oldVal).removeAll();
        ((ArrayNode) oldVal).addAll((ArrayNode) newVal);
      } else if (oldVal.isObject() && newVal.isObject()) {
        merge((ObjectNode) oldVal, (ObjectNode) newVal);
      } else if (!(newVal == null || newVal.isNull())) {
        to.set(newFieldName, newVal);
      }
    }
  }
}

代码示例来源:origin: schibsted/jslt

private ArrayNode concatenateArrays(JsonNode v1, JsonNode v2) {
 // .addAll is faster than many .add() calls
 ArrayNode result = NodeUtils.mapper.createArrayNode();
 result.addAll((ArrayNode) v1);
 result.addAll((ArrayNode) v2);
 return result;
}

代码示例来源:origin: jasminb/jsonapi-converter

private ObjectNode addIncludedSection(ObjectNode rootNode, Map<String, ObjectNode> includedDataMap) {
  if (!includedDataMap.isEmpty()) {
    ArrayNode includedArray = objectMapper.createArrayNode();
    includedArray.addAll(includedDataMap.values());
    rootNode.set(INCLUDED, includedArray);
  }
  return rootNode;
}

代码示例来源:origin: net.thisptr/jackson-jq

public static ArrayNode asArrayNode(final ObjectMapper mapper, final List<JsonNode> values) {
  final ArrayNode result = mapper.createArrayNode();
  result.addAll(values);
  return result;
}

代码示例来源:origin: io.burt/jmespath-jackson

@Override
public JsonNode createArray(Collection<JsonNode> elements) {
 ArrayNode array = JsonNodeFactory.instance.arrayNode();
 array.addAll(elements);
 return array;
}

代码示例来源:origin: basho/riak-java-client

private ArrayNode flattenResults()
{
  final JsonNodeFactory factory = JsonNodeFactory.instance;
  ArrayNode flatArray = factory.arrayNode();
  for (Map.Entry<Integer, ArrayNode> entry : results.entrySet())
  {
    flatArray.addAll(entry.getValue());
  }
  return flatArray;
}

代码示例来源:origin: eiiches/jackson-jq

public static ArrayNode asArrayNode(final ObjectMapper mapper, final List<JsonNode> values) {
  final ArrayNode result = mapper.createArrayNode();
  result.addAll(values);
  return result;
}

代码示例来源:origin: apache/lens

@Override
 public void build(ObjectNode targetNode, List<JsonNode> innerNodes) {
  final ArrayNode subTrees = JSON_NODE_FACTORY.arrayNode();
  subTrees.addAll(innerNodes);
  targetNode.put("and", subTrees);
 }
},

代码示例来源:origin: strimzi/strimzi-kafka-operator

private <E extends Enum<E>> ArrayNode enumCaseArray(E[] values) {
  ArrayNode arrayNode = nf.arrayNode();
  arrayNode.addAll(Schema.enumCases(values));
  return arrayNode;
}

代码示例来源:origin: net.thisptr/jackson-jq

@Override
public List<JsonNode> apply(final Scope scope, final JsonNode in) throws JsonQueryException {
  final ArrayNode array = new ArrayNode(scope.getObjectMapper().getNodeFactory());
  if (q != null)
    array.addAll(q.apply(scope, in));
  return Collections.singletonList((JsonNode) array);
}

代码示例来源:origin: eiiches/jackson-jq

@Override
public List<JsonNode> apply(final Scope scope, final JsonNode in) throws JsonQueryException {
  final ArrayNode array = new ArrayNode(scope.getObjectMapper().getNodeFactory());
  if (q != null)
    array.addAll(q.apply(scope, in));
  return Collections.singletonList((JsonNode) array);
}

相关文章