All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.fge.jsonpatch.operation.MoveOptionalOperation Maven / Gradle / Ivy

Go to download

JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7386) implementation in Java

The newest version!
package com.github.fge.jsonpatch.operation;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.jsonpointer.JsonPointer;
import com.github.fge.jsonpatch.JsonPatchException;
import com.github.fge.jsonpatch.operation.policy.PathMissingPolicy;

/**
 * JSON Patch {@code move?} operation
 *
 * 

For this operation, {@code from} points to the value to move, and {@code * path} points to the new location of the moved value.

* *

As for {@code add}:

* *
    *
  • the value at the destination path is either created or replaced;
  • *
  • it is created only if the immediate parent exists;
  • *
  • {@code -} appends at the end of an array.
  • *
* *

It is no error condition if {@code from} does not point to a JSON value, * in this case nothing is done. *

* *

The specification adds another rule that the {@code from} path must not be * an immediate parent of {@code path}. Unfortunately, that doesn't really work. * Consider this patch:

* *
 *     { "op": "move", "from": "/0", "path": "/0/x" }
 * 
* *

Even though {@code /0} is an immediate parent of {@code /0/x}, when this * patch is applied to:

* *
 *     [ "victim", {} ]
 * 
* *

it actually succeeds and results in the patched value:

* *
 *     [ { "x": "victim" } ]
 * 
*/ public final class MoveOptionalOperation extends MoveOperationBase { public static final String OPERATION_NAME = "move?"; @JsonCreator public MoveOptionalOperation(@JsonProperty("from") final JsonPointer from, @JsonProperty("path") final JsonPointer path) { super(OPERATION_NAME, from, path, PathMissingPolicy.SKIP); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy