本文整理了Java中com.fasterxml.jackson.databind.JsonNode.deepCopy()
方法的一些代码示例,展示了JsonNode.deepCopy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.deepCopy()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:deepCopy
[英]Method that can be called to get a node that is guaranteed not to allow changing of this node through mutators on this node or any of its children. This means it can either make a copy of this node (and all mutable children and grand children nodes), or node itself if it is immutable.
Note: return type is guaranteed to have same type as the node method is called on; which is why method is declared with local generic type.
[中]方法,该方法可被调用以获取一个节点,该节点保证不允许通过此节点或其任何子节点上的变异器更改此节点。这意味着它可以创建此节点(以及所有可变子节点和大子节点)的副本,也可以创建不可变的节点本身。
注意:返回类型保证与调用节点方法的类型相同;这就是为什么方法是用局部泛型类型声明的。
代码示例来源:origin: redisson/redisson
@SuppressWarnings("unchecked")
@Override
public ArrayNode deepCopy()
{
ArrayNode ret = new ArrayNode(_nodeFactory);
for (JsonNode element: _children)
ret._children.add(element.deepCopy());
return ret;
}
代码示例来源:origin: redisson/redisson
@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;
}
代码示例来源:origin: stagemonitor/stagemonitor
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);
}
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
ObjectNode typeNode = (ObjectNode)node.deepCopy();
typeNode.remove("javaType");
代码示例来源:origin: line/centraldogma
/**
* 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();
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
/**
* 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();
}
代码示例来源:origin: com.unboundid.product.scim2/scim2-sdk-common
/**
* {@inheritDoc}
*/
@Override
public JsonNode getJsonNode()
{
return value.deepCopy();
}
代码示例来源:origin: cwensel/cascading
@Override
public JsonNode deepCopy( JsonNode jsonNode )
{
if( jsonNode == null )
return null;
return jsonNode.deepCopy();
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded
/**
* 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();
}
代码示例来源:origin: io.swagger/swagger-compat-spec-parser
/**
* 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;
}
代码示例来源:origin: line/centraldogma
@JsonCreator
SafeReplaceOperation(@JsonProperty("path") final JsonPointer path,
@JsonProperty("oldValue") JsonNode oldValue,
@JsonProperty("value") JsonNode newValue) {
super("safeReplace", path);
this.oldValue = oldValue.deepCopy();
this.newValue = newValue.deepCopy();
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
@JsonCreator
SafeReplaceOperation(@JsonProperty("path") final JsonPointer path,
@JsonProperty("oldValue") JsonNode oldValue,
@JsonProperty("value") JsonNode newValue) {
super("safeReplace", path);
this.oldValue = oldValue.deepCopy();
this.newValue = newValue.deepCopy();
}
代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all
@SuppressWarnings("unchecked")
@Override
public ArrayNode deepCopy()
{
ArrayNode ret = new ArrayNode(_nodeFactory);
for (JsonNode element: _children)
ret._children.add(element.deepCopy());
return ret;
}
代码示例来源:origin: flipkart-incubator/zjsonpatch
@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);
}
代码示例来源:origin: com.reprezen.genflow/genflow-api
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
}
}
代码示例来源:origin: flipkart-incubator/zjsonpatch
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;
}
代码示例来源:origin: java-json-tools/json-patch
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;
}
}
代码示例来源:origin: io.wcm.caravan/io.wcm.caravan.pipeline.extensions.hal
@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()));
}
代码示例来源:origin: line/centraldogma
@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);
}
}
代码示例来源:origin: java-json-tools/json-patch
@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);
}
}
内容来源于网络,如有侵权,请联系作者删除!