Class JsonPatchImpl
java.lang.Object
org.glassfish.json.JsonPatchImpl
- All Implemented Interfaces:
JsonPatch
This class is an immutable representation of a JSON Patch as specified in
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);
- Since:
- 1.1
-
Nested Class Summary
Nested classes/interfaces inherited from interface JsonPatch
JsonPatch.Operation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(JsonStructure target) Applies the patch operations to the specifiedtarget.static JsonArraydiff(JsonStructure source, JsonStructure target) Generates a JSON Patch from the source and targetJsonStructure.booleanCompares thisJsonPatchImplwith another object.inthashCode()Returns the hash code value for thisJsonPatchImpl.Returns theJsonPatchasJsonArray.toString()Returns the JSON Patch text
-
Constructor Details
-
JsonPatchImpl
-
-
Method Details
-
equals
-
hashCode
-
toString
-
apply
Applies the patch operations to the specifiedtarget. The target is not modified by the patch.- Specified by:
applyin interfaceJsonPatch- Parameters:
target- the target to apply the patch operations- Returns:
- the transformed target after the patch
- Throws:
JsonException- if the supplied JSON Patch is malformed or if it contains references to non-existing members
-
toJsonArray
Description copied from interface:JsonPatchReturns theJsonPatchasJsonArray.- Specified by:
toJsonArrayin interfaceJsonPatch- Returns:
- this
JsonPatchasJsonArray
-
diff
Generates a JSON Patch from the source and targetJsonStructure. The generated JSON Patch need not be unique.- Parameters:
source- the sourcetarget- the target, must be the same type as the source- Returns:
- a JSON Patch which when applied to the source, yields the target
-