source: josm/trunk/src/javax/json/JsonPatchBuilder.java@ 13905

Last change on this file since 13905 was 13231, checked in by Don-vip, 7 years ago

see #15682 - upgrade to JSR 374 (JSON Processing) API 1.1.2

File size: 7.3 KB
Line 
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright (c) 2015-2017 Oracle and/or its affiliates. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can
10 * obtain a copy of the License at
11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
12 * or LICENSE.txt. See the License for the specific
13 * language governing permissions and limitations under the License.
14 *
15 * When distributing the software, include this License Header Notice in each
16 * file and include the License file at LICENSE.txt.
17 *
18 * GPL Classpath Exception:
19 * Oracle designates this particular file as subject to the "Classpath"
20 * exception as provided by Oracle in the GPL Version 2 section of the License
21 * file that accompanied this code.
22 *
23 * Modifications:
24 * If applicable, add the following below the License Header, with the fields
25 * enclosed by brackets [] replaced by your own identifying information:
26 * "Portions Copyright [year] [name of copyright owner]"
27 *
28 * Contributor(s):
29 * If you wish your version of this file to be governed by only the CDDL or
30 * only the GPL Version 2, indicate your decision by adding "[Contributor]
31 * elects to include this software in this distribution under the [CDDL or GPL
32 * Version 2] license." If you don't indicate a single choice of license, a
33 * recipient has the option to distribute your version of this file under
34 * either the CDDL, the GPL Version 2 or to extend the choice of license to
35 * its licensees as provided above. However, if you add GPL Version 2 code
36 * and therefore, elected the GPL Version 2 license, then the option applies
37 * only if the new code is made subject to such option by the copyright
38 * holder.
39 */
40
41package javax.json;
42
43/**
44 * A builder for constructing a JSON Patch as defined by
45 * <a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a> by adding
46 * JSON Patch operations incrementally.
47 * <p>
48 * The following illustrates the approach.
49 * <pre>
50 * JsonPatchBuilder builder = Json.createPatchBuilder();
51 * JsonPatch patch = builder.add("/John/phones/office", "1234-567")
52 * .remove("/Amy/age")
53 * .build();
54 * </pre>
55 * The result is equivalent to the following JSON Patch.
56 * <pre>
57 * [
58 * {"op" = "add", "path" = "/John/phones/office", "value" = "1234-567"},
59 * {"op" = "remove", "path" = "/Amy/age"}
60 * ] </pre>
61 *
62 * @see <a href="http://tools.ietf.org/html/rfc6902">RFC 6902</a>
63 *
64 * @since 1.1
65 */
66public interface JsonPatchBuilder {
67
68 /**
69 * Adds an "add" JSON Patch operation.
70 *
71 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer.
72 * @param value the "value" member of the operation
73 * @return this JsonPatchBuilder
74 */
75 JsonPatchBuilder add(String path, JsonValue value);
76
77 /**
78 * Adds an "add" JSON Patch operation.
79 *
80 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer.
81 * @param value the "value" member of the operation
82 * @return this JsonPatchBuilder
83 */
84 JsonPatchBuilder add(String path, String value);
85
86 /**
87 * Adds an "add" JSON Patch operation.
88 *
89 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer.
90 * @param value the "value" member of the operation
91 * @return this JsonPatchBuilder
92 */
93 JsonPatchBuilder add(String path, int value);
94
95 /**
96 * Adds an "add" JSON Patch operation.
97 *
98 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer.
99 * @param value the "value" member of the operation
100 * @return this JsonPatchBuilder
101 */
102 JsonPatchBuilder add(String path, boolean value);
103
104 /**
105 * Adds a "remove" JSON Patch operation.
106 *
107 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer.
108 * @return this JsonPatchBuilder
109 */
110 JsonPatchBuilder remove(String path);
111
112 /**
113 * Adds a "replace" JSON Patch operation.
114 *
115 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer.
116 * @param value the "value" member of the operation
117 * @return this JsonPatchBuilder
118 */
119 JsonPatchBuilder replace(String path, JsonValue value);
120
121 /**
122 * Adds a "replace" JSON Patch operation.
123 *
124 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer string.
125 * @param value the "value" member of the operation
126 * @return this JsonPatchBuilder
127 */
128 JsonPatchBuilder replace(String path, String value);
129
130 /**
131 * Adds a "replace" JSON Patch operation.
132 *
133 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer string.
134 * @param value the "value" member of the operation
135 * @return this JsonPatchBuilder
136 */
137 JsonPatchBuilder replace(String path, int value);
138
139 /**
140 * Adds a "replace" JSON Patch operation.
141 *
142 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer string.
143 * @param value the "value" member of the operation
144 * @return this JsonPatchBuilder
145 */
146 JsonPatchBuilder replace(String path, boolean value);
147
148 /**
149 * Adds a "move" JSON Patch operation.
150 *
151 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer string.
152 * @param from the "from" member of the operation
153 * @return this JsonPatchBuilder
154 */
155 JsonPatchBuilder move(String path, String from);
156
157 /**
158 * Adds a "copy" JSON Patch operation.
159 *
160 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer string.
161 * @param from the "from" member of the operation
162 * @return this JsonPatchBuilder
163 */
164 JsonPatchBuilder copy(String path, String from);
165
166 /**
167 * Adds a "test" JSON Patch operation.
168 *
169 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer string.
170 * @param value the "value" member of the operation
171 * @return this JsonPatchBuilder
172 */
173 JsonPatchBuilder test(String path, JsonValue value);
174
175 /**
176 * Adds a "test" JSON Patch operation.
177 *
178 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer string.
179 * @param value the "value" member of the operation
180 * @return this JsonPatchBuilder
181 */
182 JsonPatchBuilder test(String path, String value);
183
184 /**
185 * Adds a "test" JSON Patch operation.
186 *
187 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer string.
188 * @param value the "value" member of the operation
189 * @return this JsonPatchBuilder
190 */
191 JsonPatchBuilder test(String path, int value);
192
193 /**
194 * Adds a "test" JSON Patch operation.
195 *
196 * @param path the "path" member of the operation. Must be a valid escaped JSON-Pointer string.
197 * @param value the "value" member of the operation
198 * @return this JsonPatchBuilder
199 */
200 JsonPatchBuilder test(String path, boolean value);
201
202
203 /**
204 * Returns the JSON Patch.
205 *
206 * @return a JSON Patch
207 */
208 JsonPatch build();
209
210}
Note: See TracBrowser for help on using the repository browser.