Package javax.json
Interface JsonPatchBuilder
public interface JsonPatchBuilder
TODO this is a final class in the spec, but that makes no sense.
This class can be used to easily create
JsonPatches.
To get an instance use Json.createPatchBuilder() or Json.createPatchBuilder(JsonArray)
The order of the operations corresponds to the order they are builded.
NOTICE: A JsonPatchBuilder contains state and therefore is NOT threadsafe and should not be used concurrently.
The following JsonPatch
"[
{
"op": "add",
"path": "/add/object",
"value": {
"foo": "bar"
}
},
{
"op": "remove",
"path": "/remove/it"
},
{
"op": "move",
"path": "move/to",
"from": "move/from"
}
]"
can be build with the JsonPatchBuilder
JsonPatch patch = Json.createJsonPatchBuilder()
.add("/add/object", Json.createObjectBuilder()
.add("foo", "bar")
.build())
.remove("/remove/it")
.move("/move/to", "move/from")
.build();
An instance of a JsonPatchBuilder can be reused for another JsonPatch after
the build()-Method was called.
-
Method Summary
-
Method Details
-
add
Adds an 'add'-operation to theJsonPatch- Parameters:
path- asJsonPointerwhere the value should be addedvalue- the value to add- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException- if the givenpathisnull
-
add
- See Also:
-
add
- See Also:
-
add
- See Also:
-
remove
Adds a 'remove'-operation to theJsonPatch- Parameters:
path- asJsonPointerof the value which should get removed- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException- if the givenpathisnull
-
replace
Adds a 'replace'-operation to theJsonPatch- Parameters:
path- asJsonPointerto the value which should get replacedvalue- the new value- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException- if the givenpathisnull
-
replace
- See Also:
-
replace
- See Also:
-
replace
- See Also:
-
move
Adds a 'move'-operation to theJsonPatch- Parameters:
path- where the value should get inserted asJsonPointerfrom- where the value should be taken from asJsonPointer- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException- if the givenpathisnullif the givenfromisnull
-
copy
Adds a 'copy'-operation to theJsonPatch- Parameters:
path- where the copied value should get inserted asJsonPointerfrom- value to copy asJsonPointer- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException- if the givenpathisnullif the givenfromisnull
-
test
Adds a 'test'-operation to theJsonPointer- Parameters:
path- asJsonPointerto the value to testvalue- value to test- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException- if the givenpathisnull
-
test
- See Also:
-
test
- See Also:
-
test
- See Also:
-
build
JsonPatch build()
-