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
JsonPatch
es.
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
- asJsonPointer
where the value should be addedvalue
- the value to add- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException
- if the givenpath
isnull
-
add
- See Also:
-
add
- See Also:
-
add
- See Also:
-
remove
Adds a 'remove'-operation to theJsonPatch
- Parameters:
path
- asJsonPointer
of the value which should get removed- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException
- if the givenpath
isnull
-
replace
Adds a 'replace'-operation to theJsonPatch
- Parameters:
path
- asJsonPointer
to the value which should get replacedvalue
- the new value- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException
- if the givenpath
isnull
-
replace
- See Also:
-
replace
- See Also:
-
replace
- See Also:
-
move
Adds a 'move'-operation to theJsonPatch
- Parameters:
path
- where the value should get inserted asJsonPointer
from
- where the value should be taken from asJsonPointer
- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException
- if the givenpath
isnull
if the givenfrom
isnull
-
copy
Adds a 'copy'-operation to theJsonPatch
- Parameters:
path
- where the copied value should get inserted asJsonPointer
from
- value to copy asJsonPointer
- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException
- if the givenpath
isnull
if the givenfrom
isnull
-
test
Adds a 'test'-operation to theJsonPointer
- Parameters:
path
- asJsonPointer
to the value to testvalue
- value to test- Returns:
- the builder instance for chained method calls
- Throws:
NullPointerException
- if the givenpath
isnull
-
test
- See Also:
-
test
- See Also:
-
test
- See Also:
-
build
JsonPatch build()
-