Class JsonPatchBuilderImpl
java.lang.Object
org.eclipse.parsson.JsonPatchBuilderImpl
- All Implemented Interfaces:
jakarta.json.JsonPatchBuilder
A builder for constructing a JSON Patch by adding
JSON Patch operations incrementally.
The following illustrates the approach.
JsonPatchBuilder builder = Json.createPatchBuilder();
JsonPatch patch = builder.add("/John/phones/office", "1234-567")
.remove("/Amy/age")
.build();
The result is equivalent to the following JSON Patch.
[
{"op" = "add", "path" = "/John/phones/office", "value" = "1234-567"},
{"op" = "remove", "path" = "/Amy/age"}
] - Since:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final jakarta.json.JsonArrayBuilderprivate final JsonContext -
Constructor Summary
ConstructorsConstructorDescriptionJsonPatchBuilderImpl(jakarta.json.JsonArray patch, JsonContext jsonContext) Creates a JsonPatchBuilderImpl, starting with the specified JSON PatchJsonPatchBuilderImpl(JsonContext jsonContext) Creates JsonPatchBuilderImpl with empty JSON Patch -
Method Summary
Modifier and TypeMethodDescriptionjakarta.json.JsonPatchBuilderAdds an "add" JSON Patch operationjakarta.json.JsonPatchBuilderAdds an "add" JSON Patch operationjakarta.json.JsonPatchBuilderAdds an "add" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds an "add" JSON Patch operation<T extends jakarta.json.JsonStructure>
Tapply(T target) A convenience method fornew JsonPatchImpl(build()).apply(target).jakarta.json.JsonPatchbuild()Returns the patch operation in a JsonPatchjakarta.json.JsonArrayReturns the patch operations in a JsonArrayjakarta.json.JsonPatchBuilderAdds a "copy" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "move" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "remove" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "replace" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "replace" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "replace" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "replace" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "test" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "test" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "test" JSON Patch operation.jakarta.json.JsonPatchBuilderAdds a "test" JSON Patch operation.
-
Field Details
-
jsonContext
-
builder
private final jakarta.json.JsonArrayBuilder builder
-
-
Constructor Details
-
JsonPatchBuilderImpl
Creates a JsonPatchBuilderImpl, starting with the specified JSON Patch- Parameters:
patch- the JSON Patch
-
JsonPatchBuilderImpl
Creates JsonPatchBuilderImpl with empty JSON Patch
-
-
Method Details
-
apply
public <T extends jakarta.json.JsonStructure> T apply(T target) A convenience method fornew JsonPatchImpl(build()).apply(target). The target is not modified by the patch.- Type Parameters:
T- the target type, must be a subtype ofJsonStructure- Parameters:
target- the target to apply the patch operations- Returns:
- the transformed target after the patch
- Throws:
jakarta.json.JsonException- if the supplied JSON Patch is malformed or if it contains references to non-existing members
-
add
Adds an "add" JSON Patch operation.- Specified by:
addin interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
add
-
add
Adds an "add" JSON Patch operation- Specified by:
addin interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
add
Adds an "add" JSON Patch operation- Specified by:
addin interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
remove
Adds a "remove" JSON Patch operation.- Specified by:
removein interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operation- Returns:
- this JsonPatchBuilder
-
replace
Adds a "replace" JSON Patch operation.- Specified by:
replacein interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
replace
Adds a "replace" JSON Patch operation.- Specified by:
replacein interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
replace
Adds a "replace" JSON Patch operation.- Specified by:
replacein interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
replace
Adds a "replace" JSON Patch operation.- Specified by:
replacein interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
move
-
copy
-
test
Adds a "test" JSON Patch operation.- Specified by:
testin interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
test
-
test
Adds a "test" JSON Patch operation.- Specified by:
testin interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
test
Adds a "test" JSON Patch operation.- Specified by:
testin interfacejakarta.json.JsonPatchBuilder- Parameters:
path- the "path" member of the operationvalue- the "value" member of the operation- Returns:
- this JsonPatchBuilder
-
buildAsJsonArray
public jakarta.json.JsonArray buildAsJsonArray()Returns the patch operations in a JsonArray- Returns:
- the patch operations in a JsonArray
-
build
public jakarta.json.JsonPatch build()Returns the patch operation in a JsonPatch- Specified by:
buildin interfacejakarta.json.JsonPatchBuilder- Returns:
- the patch operation in a JsonPatch
-