com.github.fge.jsonpatch.operation.MoveOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-patch Show documentation
Show all versions of json-patch Show documentation
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 an error condition if {@code from} does not point to a JSON value.
*
*
* 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 MoveOperation
extends MoveOperationBase
{
public static final String OPERATION_NAME = "move";
@JsonCreator
public MoveOperation(@JsonProperty("from") final JsonPointer from,
@JsonProperty("path") final JsonPointer path)
{
super(OPERATION_NAME, from, path, PathMissingPolicy.THROW);
}
}