-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathAddOperation.java
More file actions
70 lines (66 loc) · 1.96 KB
/
AddOperation.java
File metadata and controls
70 lines (66 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2014, Francis Galiegue (fgaliegue@gmail.com)
*
* This software is dual-licensed under:
*
* - the Lesser General Public License (LGPL) version 3.0 or, at your option, any
* later version;
* - the Apache Software License (ASL) version 2.0.
*
* The text of both licenses is available under the src/resources/ directory of
* this project (under the names LGPL-3.0.txt and ASL-2.0.txt respectively).
*
* Direct link to the sources:
*
* - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
* - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
*/
package com.github.fge.jsonpatch;
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;
/**
* JSON Patch {@code add} operation
*
* <p>For this operation, {@code path} is the JSON Pointer where the value
* should be added, and {@code value} is the value to add.</p>
*
* <p>Note that if the target value pointed to by {@code path} already exists,
* it is replaced. In this case, {@code add} is equivalent to {@code replace}.
* </p>
*
* <p>Note also that a value will be created at the target path <b>if and only
* if</b> the immediate parent of that value exists (and is of the correct
* type).</p>
*
* <p>Finally, if the last reference token of the JSON Pointer is {@code -} and
* the immediate parent is an array, the given value is added at the end of the
* array. For instance, applying:</p>
*
* <pre>
* { "op": "add", "path": "/-", "value": 3 }
* </pre>
*
* <p>to:</p>
*
* <pre>
* [ 1, 2 ]
* </pre>
*
* <p>will give:</p>
*
* <pre>
* [ 1, 2, 3 ]
* </pre>
*/
public final class AddOperation
extends AdditionOperation
{
@JsonCreator
public AddOperation(@JsonProperty("path") final JsonPointer path,
@JsonProperty("value") final JsonNode value)
{
super("add", path, value, true);
}
}