com.github.fge.jsonpatch
Class AddOperation

java.lang.Object
  extended by com.github.fge.jsonpatch.JsonPatchOperation
      extended by com.github.fge.jsonpatch.PathValueOperation
          extended by com.github.fge.jsonpatch.AddOperation
All Implemented Interfaces:
JsonSerializable

public final class AddOperation
extends PathValueOperation

JSON Patch add operation

For this operation, path is the JSON Pointer where the value should be added, and value is the value to add.

Note that if the target value pointed to by path already exists, it is replaced. In this case, add is equivalent to replace.

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 inherited from class com.github.fge.jsonpatch.PathValueOperation
value
 
Fields inherited from class com.github.fge.jsonpatch.JsonPatchOperation
BUNDLE, op, path
 
Constructor Summary
AddOperation(JsonPointer path, JsonNode value)
           
 
Method Summary
 JsonNode apply(JsonNode node)
          Apply this operation to a JSON value
 
Methods inherited from class com.github.fge.jsonpatch.PathValueOperation
serialize, serializeWithType, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AddOperation

public AddOperation(JsonPointer path,
                    JsonNode value)
Method Detail

apply

public JsonNode apply(JsonNode node)
               throws JsonPatchException
Description copied from class: JsonPatchOperation
Apply this operation to a JSON value

Specified by:
apply in class JsonPatchOperation
Parameters:
node - the value to patch
Returns:
the patched value
Throws:
JsonPatchException - operation failed to apply to this value