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); } } }
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); } }
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); } }
@Override public void insert(int index, JzonElement el) { wrapped.insert(index, (JsonNode) el.unwrap()); }
@Override public void insert(int index, JzonElement el) { wrapped.insert(index, (JsonNode) el.unwrap()); }
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); } } } }
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)); } } }
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; }
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; }
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; }
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; }
transformationsNode.insert(order, transformationNode);
transformationsNode.insert(order, transformationNode);
arrayNode.insert(insertTo, newValueNode); } else { arrayNode.add(newValueNode);
arrayNode.insert(insertTo, newValueNode); } else { arrayNode.add(newValueNode);
arrayNode.insert(insertTo, newValueNode); } else { arrayNode.add(newValueNode);
chainsList.insert(beforePos, chainNode);
chainsList.insert(beforePos, chainNode);