public class JsonPatch extends Object
A JsonPatch
can be instantiated with JsonPatch(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 = new JsonPatch(patch);
JsonArray result = jsonpatch.apply(contacts);
2. Construct a JsonPatch with JsonPatchBuilder.
JsonPatchBuilder builder = new JsonPatchBuilder();
JsonArray result = builder.add("/John/phones/office", "1234-567")
.remove("/Amy/age")
.apply(contacts);
Constructor and Description |
---|
JsonPatch(JsonArray patch)
Constructs a JsonPatch
|
Modifier and Type | Method and Description |
---|---|
JsonArray |
apply(JsonArray target)
Applies the patch operations to the specified
target . |
JsonObject |
apply(JsonObject target)
Applies the patch operations to the specified
target . |
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
JsonPatch with another object. |
int |
hashCode()
Returns the hash code value for this
JsonPatch . |
String |
toString()
Returns the JSON Patch text
|
public JsonPatch(JsonArray patch)
patch
- the JSON Patchpublic boolean equals(Object obj)
JsonPatch
with another object.public int hashCode()
JsonPatch
.public String toString()
public JsonStructure apply(JsonStructure target)
target
.
The target is not modified by the patch.target
- the target to apply the patch operationsJsonException
- if the supplied JSON Patch is malformed or if
it contains references to non-existing memberspublic JsonObject apply(JsonObject target)
target
.target
- the target to apply the patch operationsJsonException
- if the supplied JSON Patch is malformed or if
it contains references to non-existing memberspublic JsonArray apply(JsonArray target)
target
.target
- the target to apply the patch operationsJsonException
- if the supplied JSON Patch is malformed or if
it contains references to non-existing memberspublic 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 © 2012-2015, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.
Comments to : [email protected]