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