public interface JsonPatch
This interface represents an immutable implementation of a JSON Patch as defined by RFC 6902.
A JsonPatch
can be instantiated with Json.createPatch(JsonArray)
by specifying the patch operations in a JSON Patch. Alternately, it
can also be constructed with a JsonPatchBuilder
.
1. Construct a JsonPatch with a JSON Patch.
JsonArray contacts = ... // The target to be patched
JsonArray patch = ... ; // JSON Patch
JsonPatch jsonpatch = Json.createPatch(patch);
JsonArray result = jsonpatch.apply(contacts);
2. Construct a JsonPatch with JsonPatchBuilder.
JsonPatchBuilder builder = Json.createPatchBuilder();
JsonArray result = builder.add("/John/phones/office", "1234-567")
.remove("/Amy/age")
.build()
.apply(contacts);
Modifier and Type | Interface and Description |
---|---|
static class |
JsonPatch.Operation
This enum represents the list of valid JSON Patch operations
as defined by RFC 6902.
|
Modifier and Type | Method and Description |
---|---|
<T extends JsonStructure> |
apply(T target)
Applies the patch operations to the specified
target . |
JsonArray |
toJsonArray()
Returns the
JsonPatch as JsonArray . |
<T extends JsonStructure> T apply(T target)
target
.
The target is not modified by the patch.T
- the target type, must be a subtype of JsonStructure
target
- the target to apply the patch operationsJsonException
- if the supplied JSON Patch is malformed or if
it contains references to non-existing membersJsonArray toJsonArray()
JsonPatch
as JsonArray
.JsonPatch
as JsonArray
Copyright © 2019 JBoss by Red Hat. All rights reserved.