JsonPatchpublic class JsonPatchImpl extends Object implements JsonPatch
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);
JsonPatch.Operation| Constructor | Description |
|---|---|
JsonPatchImpl(JsonArray patch) |
Constructs a JsonPatchImpl
|
| Modifier and Type | Method | Description |
|---|---|---|
JsonStructure |
apply(JsonStructure target) |
Applies the patch operations to the specified
target. |
static JsonArray |
diff(JsonStructure source,
JsonStructure target) |
Generates a JSON Patch from the source and target
JsonStructure. |
boolean |
equals(Object obj) |
Compares this
JsonPatchImpl with another object. |
int |
hashCode() |
Returns the hash code value for this
JsonPatchImpl. |
JsonArray |
toJsonArray() |
Returns the
JsonPatch as JsonArray. |
String |
toString() |
Returns the JSON Patch text
|
public JsonPatchImpl(JsonArray patch)
patch - the JSON Patchpublic boolean equals(Object obj)
JsonPatchImpl with another object.public int hashCode()
JsonPatchImpl.public String toString()
public JsonStructure apply(JsonStructure target)
target.
The target is not modified by the patch.apply in interface JsonPatchtarget - the target to apply the patch operationsJsonException - if the supplied JSON Patch is malformed or if
it contains references to non-existing memberspublic JsonArray toJsonArray()
JsonPatchJsonPatch as JsonArray.toJsonArray in interface JsonPatchJsonPatch as JsonArraypublic static JsonArray diff(JsonStructure source, JsonStructure target)
JsonStructure.
The generated JSON Patch need not be unique.source - the sourcetarget - the target, must be the same type as the sourceCopyright © 2017 Oracle. All rights reserved.