Class AddOperation
- java.lang.Object
-
- com.github.fge.jsonpatch.operation.PathValueOperation
-
- com.github.fge.jsonpatch.operation.AddOperation
-
- All Implemented Interfaces:
com.fasterxml.jackson.databind.JsonSerializable,JsonPatchOperation
public class AddOperation extends PathValueOperation
JSON PatchaddoperationFor this operation,
pathis the JSON Pointer where the value should be added, andvalueis the value to add.Note that if the target value pointed to by
pathalready exists, it is replaced. In this case,addis equivalent toreplace.Note also that a value will be created at the target path if and only if the immediate parent of that value exists (and is of the correct type).
Finally, if the last reference token of the JSON Pointer is
-and the immediate parent is an array, the given value is added at the end of the array. For instance, applying:{ "op": "add", "path": "/-", "value": 3 }to:
[ 1, 2 ]will give:
[ 1, 2, 3 ]
-
-
Field Summary
Fields Modifier and Type Field Description protected static com.github.fge.jackson.jsonpointer.ReferenceTokenLAST_ARRAY_ELEMENTstatic StringOPERATION_NAME-
Fields inherited from class com.github.fge.jsonpatch.operation.PathValueOperation
BUNDLE, op, path, value
-
-
Constructor Summary
Constructors Constructor Description AddOperation(com.github.fge.jackson.jsonpointer.JsonPointer path, com.fasterxml.jackson.databind.JsonNode value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.fasterxml.jackson.databind.JsonNodeaddToArray(com.github.fge.jackson.jsonpointer.JsonPointer path, com.fasterxml.jackson.databind.JsonNode node)protected com.fasterxml.jackson.databind.JsonNodeaddToObject(com.github.fge.jackson.jsonpointer.JsonPointer path, com.fasterxml.jackson.databind.JsonNode node)com.fasterxml.jackson.databind.JsonNodeapply(com.fasterxml.jackson.databind.JsonNode node)Apply this operation to a JSON value-
Methods inherited from class com.github.fge.jsonpatch.operation.PathValueOperation
serialize, serializeWithType, toString
-
-
-
-
Field Detail
-
OPERATION_NAME
public static final String OPERATION_NAME
- See Also:
- Constant Field Values
-
LAST_ARRAY_ELEMENT
protected static final com.github.fge.jackson.jsonpointer.ReferenceToken LAST_ARRAY_ELEMENT
-
-
Method Detail
-
apply
public com.fasterxml.jackson.databind.JsonNode apply(com.fasterxml.jackson.databind.JsonNode node) throws JsonPatchExceptionDescription copied from interface:JsonPatchOperationApply this operation to a JSON value- Parameters:
node- the value to patch- Returns:
- the patched value
- Throws:
JsonPatchException- operation failed to apply to this value
-
addToArray
protected com.fasterxml.jackson.databind.JsonNode addToArray(com.github.fge.jackson.jsonpointer.JsonPointer path, com.fasterxml.jackson.databind.JsonNode node) throws JsonPatchException- Throws:
JsonPatchException
-
addToObject
protected com.fasterxml.jackson.databind.JsonNode addToObject(com.github.fge.jackson.jsonpointer.JsonPointer path, com.fasterxml.jackson.databind.JsonNode node)
-
-