@SuppressWarnings("unchecked") @Override public ArrayNode deepCopy() { ArrayNode ret = new ArrayNode(_nodeFactory); for (JsonNode element: _children) ret._children.add(element.deepCopy()); return ret; }
@SuppressWarnings("unchecked") @Override public ObjectNode deepCopy() { ObjectNode ret = new ObjectNode(_nodeFactory); for (Map.Entry<String, JsonNode> entry: _children.entrySet()) ret._children.put(entry.getKey(), entry.getValue().deepCopy()); return ret; }
public void updateKibanaIndexPattern(final String indexName, final String indexPatternLocation) { final String elasticsearchKibanaIndexPatternPath = isElasticsearch6Compatible() ? "/.kibana/doc/index-pattern:" + indexName : "/.kibana/index-pattern/" + indexName; logger.debug("Sending index pattern {} to {}", indexPatternLocation, elasticsearchKibanaIndexPatternPath); try { ObjectNode stagemonitorPattern = JsonUtils.getMapper().readTree(IOUtils.getResourceAsStream(indexPatternLocation)).deepCopy(); if (isElasticsearch6Compatible()) { ObjectNode indexPatternNode = (ObjectNode) stagemonitorPattern.get("index-pattern"); indexPatternNode.put("fields", getFields(stagemonitorPattern.get("index-pattern").get("fields").asText())); } else { stagemonitorPattern.put("fields", getFields(stagemonitorPattern.get("fields").asText())); } JsonNode currentPattern = fetchCurrentKibanaIndexPatternConfiguration(elasticsearchKibanaIndexPatternPath); JsonNode mergedDefinition = JsonMerger.merge(currentPattern, stagemonitorPattern, mergeStrategy().mergeEncodedObjects("fieldFormatMap").encodedArrayWithKey("fields", "name")); sendAsJson("PUT", elasticsearchKibanaIndexPatternPath, mergedDefinition); } catch (IOException e) { logger.warn("Error while updating kibana index pattern, definition = {}, pattern path = {}", indexPatternLocation, elasticsearchKibanaIndexPatternPath, e); } catch (IllegalArgumentException e) { logger.warn("Error while preparing data for kibana index pattern update, definition = {}, pattern path = {}", indexPatternLocation, elasticsearchKibanaIndexPatternPath); } }
ObjectNode typeNode = (ObjectNode)node.deepCopy(); typeNode.remove("javaType");
/** * Creates a new instance. * * @param op operation name * @param path affected path * @param value JSON value */ PathValueOperation(final String op, final JsonPointer path, final JsonNode value) { super(op, path); this.value = value.deepCopy(); }
/** * Creates a new instance. * * @param op operation name * @param path affected path * @param value JSON value */ PathValueOperation(final String op, final JsonPointer path, final JsonNode value) { super(op, path); this.value = value.deepCopy(); }
/** * {@inheritDoc} */ @Override public JsonNode getJsonNode() { return value.deepCopy(); }
@Override public JsonNode deepCopy( JsonNode jsonNode ) { if( jsonNode == null ) return null; return jsonNode.deepCopy(); }
/** * Creates a new instance. * * @param op operation name * @param path affected path * @param value JSON value */ PathValueOperation(final String op, final JsonPointer path, final JsonNode value) { super(op, path); this.value = value.deepCopy(); }
/** * Constructor * * @param node the node to transform (copied) */ public MutableJsonTree(final JsonNode node) { Objects.requireNonNull(node, "node must not be null"); baseNode = node.deepCopy(); currentNode = baseNode; }
@SuppressWarnings("unchecked") @Override public ArrayNode deepCopy() { ArrayNode ret = new ArrayNode(_nodeFactory); for (JsonNode element: _children) ret._children.add(element.deepCopy()); return ret; }
@Override public void copy(List<String> fromPath, List<String> toPath) { JsonNode parentNode = getParentNode(fromPath, Operation.COPY); String field = fromPath.get(fromPath.size() - 1).replaceAll("\"", ""); JsonNode valueNode = parentNode.isArray() ? parentNode.get(Integer.parseInt(field)) : parentNode.get(field); JsonNode valueToCopy = valueNode != null ? valueNode.deepCopy() : null; add(toPath, valueToCopy); }
private static JsonNode deepCopy(JsonNode node, IdentityHashMap<JsonNode, JsonNode> copies) { if (copies.containsKey(node)) { return copies.get(node); } if (node.isObject()) { return deepCopyObject((ObjectNode) node, copies); } else if (node.isArray()) { return deepCopyArray((ArrayNode) node, copies); } else { return node.deepCopy(); // all other node types are already safe } }
private static Integer addRemaining(List<Diff> diffs, List<Object> path, JsonNode target, int pos, int targetIdx, int targetSize) { while (targetIdx < targetSize) { JsonNode jsonNode = target.get(targetIdx); List<Object> currPath = getPath(path, pos); diffs.add(Diff.generateDiff(Operation.ADD, currPath, jsonNode.deepCopy())); pos++; targetIdx++; } return pos; }
private JsonNode addToObject(final JsonPointer path, final JsonNode node) { final JsonNode ret = node.deepCopy(); final ObjectNode target = (ObjectNode) path.parent().get(ret); target.put(Iterables.getLast(path).getToken().getRaw(), value); return ret; } }
@Override public final Observable<JsonPipelineOutput> execute(JsonPipelineOutput previousStepOutput, JsonPipelineContext pipelineContext) { if (!previousStepOutput.getPayload().isObject()) { throw new JsonPipelineOutputException(ModifyResource.class.getName() + " expects the output of the previous step to be a JSON *object* output, but got " + previousStepOutput.getPayload().toString()); } ObjectNode state = previousStepOutput.getPayload().deepCopy(); HalResource resource = new HalResource(state, selfHref); modify(resource); return Observable.just(previousStepOutput.withPayload(resource.getModel())); }
@Test(dataProvider = "getOps") public final void operationsYieldExpectedResults( final JsonNode patch, final JsonNode node, final JsonNode expected) throws IOException { final JsonPatchOperation op = reader.readValue(patch); final JsonNode actual = op.apply(node.deepCopy()); assertTrue(EQUIVALENCE.equivalent(actual, expected), "patched node differs from expectations: expected " + expected + " but found " + actual); } }
@Override public JsonNode apply(final JsonNode node) throws JsonPatchException { final JsonNode dupData = from.path(node).deepCopy(); if (dupData.isMissingNode()) throw new JsonPatchException(BUNDLE.getMessage( "jsonPatch.noSuchPath")); return new AddOperation(path, dupData).apply(node); } }