public class JsonPatchImpl extends java.lang.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 and Description |
---|
JsonPatchImpl(JsonArray patch)
Constructs a JsonPatchImpl
|
Modifier and Type | Method and 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(java.lang.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 . |
java.lang.String |
toString()
Returns the JSON Patch text
|
public JsonPatchImpl(JsonArray patch)
patch
- the JSON Patchpublic boolean equals(java.lang.Object obj)
JsonPatchImpl
with another object.equals
in class java.lang.Object
obj
- the object to compare this JsonPatchImpl
againstJsonPatchImpl
with the same
reference tokens as this one, false otherwise.public int hashCode()
JsonPatchImpl
.hashCode
in class java.lang.Object
JsonPatchImpl
objectpublic java.lang.String toString()
toString
in class java.lang.Object
public JsonStructure apply(JsonStructure target)
target
.
The target is not modified by the patch.apply
in interface JsonPatch
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 toJsonArray()
JsonPatch
JsonPatch
as JsonArray
.toJsonArray
in interface JsonPatch
JsonPatch
as JsonArray
public 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-2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.
Comments to : jsonp-dev@eclipse.org