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

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

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

ArrayNode.insert介绍

[英]Method that will insert specified numeric value at specified position in this array.
[中]方法,该方法将在此数组中的指定位置插入指定的数值。

代码示例

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

private static void mergeJsonArray(ArrayNode src, ArrayNode other) {
  for (int i = 0; i < other.size(); i++) {
    JsonNode s = src.get(i);
    JsonNode v = other.get(i);
    if (s == null) {
      src.add(v);
    } else if (v.isObject() && s.isObject()) {
      mergeJsonObject((ObjectNode) s, (ObjectNode) v);
    } else if (v.isArray() && s.isArray()) {
      mergeJsonArray((ArrayNode) s, (ArrayNode) v);
    } else {
      src.remove(i);
      src.insert(i, v);
    }
  }
}

代码示例来源:origin: com.flipkart.zjsonpatch/zjsonpatch

private void addToArray(List<String> path, JsonNode value, JsonNode parentNode) {
  final ArrayNode target = (ArrayNode) parentNode;
  String idxStr = path.get(path.size() - 1);
  if ("-".equals(idxStr)) {
    // see http://tools.ietf.org/html/rfc6902#section-4.1
    target.add(value);
  } else {
    int idx = arrayIndex(idxStr.replaceAll("\"", ""), target.size(), false);
    target.insert(idx, value);
  }
}

代码示例来源:origin: flipkart-incubator/zjsonpatch

private void addToArray(List<String> path, JsonNode value, JsonNode parentNode) {
  final ArrayNode target = (ArrayNode) parentNode;
  String idxStr = path.get(path.size() - 1);
  if ("-".equals(idxStr)) {
    // see http://tools.ietf.org/html/rfc6902#section-4.1
    target.add(value);
  } else {
    int idx = arrayIndex(idxStr.replaceAll("\"", ""), target.size(), false);
    target.insert(idx, value);
  }
}

代码示例来源:origin: com.github.foodev/jsondiff

@Override
public void insert(int index, JzonElement el) {
  wrapped.insert(index, (JsonNode) el.unwrap());
}

代码示例来源:origin: algesten/jsondiff

@Override
public void insert(int index, JzonElement el) {
  wrapped.insert(index, (JsonNode) el.unwrap());
}

代码示例来源:origin: io.fabric8/zjsonpatch

private static void addToArray(List<String> path, JsonNode value, JsonNode parentNode) {
 final ArrayNode target = (ArrayNode) parentNode;
 String idxStr = path.get(path.size() - 1);
 if ("-".equals(idxStr)) {
  // see http://tools.ietf.org/html/rfc6902#section-4.1
  target.add(value);
 } else {
  Integer idx = Integer.parseInt(idxStr.replaceAll("\"", ""));
  if (idx < target.size()) {
   target.insert(idx, value);
  } else {
   if (idx == target.size()) {
    target.add(value);
   } else {
    throw new RuntimeException("[ADD Operation] [addToArray] index Out of bound, index provided is higher than allowed, path " + path);
   }
  }
 }
}

代码示例来源:origin: org.onap.appc/appc-dg-common

private void updateJsonNode(SvcLogicContext ctx, ObjectMapper objectMapper, ObjectNode jsonNode, String key) {
  if (key.startsWith(Constants.OUTPUT_PAYLOAD + ".")) {
    String objkey = key.replaceFirst(Constants.OUTPUT_PAYLOAD + ".", "");
    if (objkey.contains("[") && objkey.contains("]")) {
      ArrayNode arrayNode;
      String arrayKey = objkey.substring(0, objkey.indexOf('['));
      int arrayIndex = Integer
        .parseInt(objkey.substring(objkey.indexOf('[') + 1, objkey.indexOf(']')));
      if (jsonNode.has(arrayKey)) {
        arrayNode = (ArrayNode) jsonNode.get(arrayKey);
        arrayNode.insert(arrayIndex, ctx.getAttribute(key));
      } else {
        arrayNode = objectMapper.createArrayNode();
        arrayNode.insert(arrayIndex, ctx.getAttribute(key));
        jsonNode.put(arrayKey, arrayNode);
      }
    } else {
      jsonNode.put(objkey, ctx.getAttribute(key));
    }
  }
}

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

static JsonNode addToArray(final JsonPointer path, final JsonNode node, final JsonNode value) {
  final ArrayNode target = (ArrayNode) node.at(path.head());
  final String rawToken = path.last().getMatchingProperty();
  if (rawToken.equals(LAST_ARRAY_ELEMENT)) {
    target.add(value);
    return node;
  }
  final int size = target.size();
  final int index;
  try {
    index = Integer.parseInt(rawToken);
  } catch (NumberFormatException ignored) {
    throw new JsonPatchException("not an index: " + rawToken + " (expected: a non-negative integer)");
  }
  if (index < 0 || index > size) {
    throw new JsonPatchException("index out of bounds: " + index +
                   " (expected: >= 0 && <= " + size + ')');
  }
  target.insert(index, value);
  return node;
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

static JsonNode addToArray(final JsonPointer path, final JsonNode node, final JsonNode value) {
  final ArrayNode target = (ArrayNode) node.at(path.head());
  final String rawToken = path.last().getMatchingProperty();
  if (rawToken.equals(LAST_ARRAY_ELEMENT)) {
    target.add(value);
    return node;
  }
  final int size = target.size();
  final int index;
  try {
    index = Integer.parseInt(rawToken);
  } catch (NumberFormatException ignored) {
    throw new JsonPatchException("not an index: " + rawToken + " (expected: a non-negative integer)");
  }
  if (index < 0 || index > size) {
    throw new JsonPatchException("index out of bounds: " + index +
                   " (expected: >= 0 && <= " + size + ')');
  }
  target.insert(index, value);
  return node;
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded

static JsonNode addToArray(final JsonPointer path, final JsonNode node, final JsonNode value) {
  final ArrayNode target = (ArrayNode) node.at(path.head());
  final String rawToken = path.last().getMatchingProperty();
  if (rawToken.equals(LAST_ARRAY_ELEMENT)) {
    target.add(value);
    return node;
  }
  final int size = target.size();
  final int index;
  try {
    index = Integer.parseInt(rawToken);
  } catch (NumberFormatException ignored) {
    throw new JsonPatchException("not an index: " + rawToken + " (expected: a non-negative integer)");
  }
  if (index < 0 || index > size) {
    throw new JsonPatchException("index out of bounds: " + index +
                   " (expected: >= 0 && <= " + size + ')');
  }
  target.insert(index, value);
  return node;
}

代码示例来源:origin: org.openecomp.appc/appc-dg-common

if(JsonNode.has(arrayKey)){
  arrayNode = (ArrayNode)JsonNode.get(arrayKey);
  arrayNode.insert(arrayIndex,ctx.getAttribute(key));
}else {
  arrayNode = objectMapper.createArrayNode();
  arrayNode.insert(arrayIndex,ctx.getAttribute(key));
  JsonNode.put(arrayKey,arrayNode);

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

private JsonNode addToArray(final JsonPointer path, final JsonNode node)
  throws JsonPatchException
{
  final JsonNode ret = node.deepCopy();
  final ArrayNode target = (ArrayNode) path.parent().get(ret);
  final TokenResolver<JsonNode> token = Iterables.getLast(path);
  if (token.getToken().equals(LAST_ARRAY_ELEMENT)) {
    target.add(value);
    return ret;
  }
  final int size = target.size();
  final int index;
  try {
    index = Integer.parseInt(token.toString());
  } catch (NumberFormatException ignored) {
    throw new JsonPatchException(BUNDLE.getMessage(
      "jsonPatch.notAnIndex"));
  }
  if (index < 0 || index > size)
    throw new JsonPatchException(BUNDLE.getMessage(
      "jsonPatch.noSuchIndex"));
  target.insert(index, value);
  return ret;
}

代码示例来源:origin: walkmod/walkmod-core

transformationsNode.insert(order, transformationNode);

代码示例来源:origin: org.walkmod/walkmod-core

transformationsNode.insert(order, transformationNode);

代码示例来源:origin: com.redhat.lightblue/crud

arrayNode.insert(insertTo, newValueNode);
} else {
  arrayNode.add(newValueNode);

代码示例来源:origin: lightblue-platform/lightblue-core

arrayNode.insert(insertTo, newValueNode);
} else {
  arrayNode.add(newValueNode);

代码示例来源:origin: com.redhat.lightblue/lightblue-core-crud

arrayNode.insert(insertTo, newValueNode);
} else {
  arrayNode.add(newValueNode);

代码示例来源:origin: org.walkmod/walkmod-core

chainsList.insert(beforePos, chainNode);

代码示例来源:origin: walkmod/walkmod-core

chainsList.insert(beforePos, chainNode);

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

相关文章