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 createJsonPatch
es. To get an instance useJson.createPatchBuilder()
orJson.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 JsonPatchBuilderJsonPatch 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 thebuild()
-Method was called.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description JsonPatchBuilder
add(java.lang.String path, boolean value)
JsonPatchBuilder
add(java.lang.String path, int value)
JsonPatchBuilder
add(java.lang.String path, java.lang.String value)
JsonPatchBuilder
add(java.lang.String path, JsonValue value)
Adds an 'add'-operation to theJsonPatch
JsonPatch
build()
JsonPatchBuilder
copy(java.lang.String path, java.lang.String from)
Adds a 'copy'-operation to theJsonPatch
JsonPatchBuilder
move(java.lang.String path, java.lang.String from)
Adds a 'move'-operation to theJsonPatch
JsonPatchBuilder
remove(java.lang.String path)
Adds a 'remove'-operation to theJsonPatch
JsonPatchBuilder
replace(java.lang.String path, boolean value)
JsonPatchBuilder
replace(java.lang.String path, int value)
JsonPatchBuilder
replace(java.lang.String path, java.lang.String value)
JsonPatchBuilder
replace(java.lang.String path, JsonValue value)
Adds a 'replace'-operation to theJsonPatch
JsonPatchBuilder
test(java.lang.String path, boolean value)
JsonPatchBuilder
test(java.lang.String path, int value)
JsonPatchBuilder
test(java.lang.String path, java.lang.String value)
JsonPatchBuilder
test(java.lang.String path, JsonValue value)
Adds a 'test'-operation to theJsonPointer
-
-
-
Method Detail
-
add
JsonPatchBuilder add(java.lang.String path, JsonValue value)
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:
java.lang.NullPointerException
- if the givenpath
isnull
-
add
JsonPatchBuilder add(java.lang.String path, java.lang.String value)
- See Also:
add(String, JsonValue)
-
add
JsonPatchBuilder add(java.lang.String path, int value)
- See Also:
add(String, JsonValue)
-
add
JsonPatchBuilder add(java.lang.String path, boolean value)
- See Also:
add(String, JsonValue)
-
remove
JsonPatchBuilder remove(java.lang.String path)
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:
java.lang.NullPointerException
- if the givenpath
isnull
-
replace
JsonPatchBuilder replace(java.lang.String path, JsonValue value)
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:
java.lang.NullPointerException
- if the givenpath
isnull
-
replace
JsonPatchBuilder replace(java.lang.String path, java.lang.String value)
- See Also:
replace(String, JsonValue)
-
replace
JsonPatchBuilder replace(java.lang.String path, int value)
- See Also:
replace(String, JsonValue)
-
replace
JsonPatchBuilder replace(java.lang.String path, boolean value)
- See Also:
replace(String, JsonValue)
-
move
JsonPatchBuilder move(java.lang.String path, java.lang.String from)
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:
java.lang.NullPointerException
- if the givenpath
isnull
if the givenfrom
isnull
-
copy
JsonPatchBuilder copy(java.lang.String path, java.lang.String from)
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:
java.lang.NullPointerException
- if the givenpath
isnull
if the givenfrom
isnull
-
test
JsonPatchBuilder test(java.lang.String path, JsonValue value)
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:
java.lang.NullPointerException
- if the givenpath
isnull
-
test
JsonPatchBuilder test(java.lang.String path, java.lang.String value)
- See Also:
test(String, JsonValue)
-
test
JsonPatchBuilder test(java.lang.String path, int value)
- See Also:
test(String, JsonValue)
-
test
JsonPatchBuilder test(java.lang.String path, boolean value)
- See Also:
test(String, JsonValue)
-
build
JsonPatch build()
-
-