Class JsonPatchImpl
java.lang.Object
org.eclipse.parsson.JsonPatchImpl
- All Implemented Interfaces:
jakarta.json.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 ClassesNested classes/interfaces inherited from interface jakarta.json.JsonPatch
jakarta.json.JsonPatch.Operation -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJsonPatchImpl(jakarta.json.JsonArray patch, JsonContext jsonContext) Constructs a JsonPatchImpl -
Method Summary
Modifier and TypeMethodDescriptionjakarta.json.JsonStructureapply(jakarta.json.JsonStructure target) Applies the patch operations to the specifiedtarget.private jakarta.json.JsonStructureapply(jakarta.json.JsonStructure target, jakarta.json.JsonObject operation) Applies a JSON Patch operation to the target.(package private) static jakarta.json.JsonArraydiff(jakarta.json.JsonStructure source, jakarta.json.JsonStructure target, JsonContext jsonContext) Generates a JSON Patch from the source and targetJsonStructure.booleanCompares thisJsonPatchImplwith another object.private jakarta.json.JsonPointergetPointer(jakarta.json.JsonObject operation, String member) private jakarta.json.JsonValuegetValue(jakarta.json.JsonObject operation) inthashCode()Returns the hash code value for thisJsonPatchImpl.private voidmissingMember(String op, String member) jakarta.json.JsonArraytoString()Returns the JSON Patch text
-
Field Details
-
patch
private final jakarta.json.JsonArray patch -
jsonContext
-
-
Constructor Details
-
JsonPatchImpl
Constructs a JsonPatchImpl- Parameters:
patch- the JSON Patch
-
-
Method Details
-
equals
-
hashCode
-
toString
-
apply
public jakarta.json.JsonStructure apply(jakarta.json.JsonStructure target) Applies the patch operations to the specifiedtarget. The target is not modified by the patch.- Specified by:
applyin interfacejakarta.json.JsonPatch- Parameters:
target- the target to apply the patch operations- Returns:
- the transformed target after the patch
- Throws:
jakarta.json.JsonException- if the supplied JSON Patch is malformed or if it contains references to non-existing members
-
toJsonArray
public jakarta.json.JsonArray toJsonArray()- Specified by:
toJsonArrayin interfacejakarta.json.JsonPatch
-
diff
static jakarta.json.JsonArray diff(jakarta.json.JsonStructure source, jakarta.json.JsonStructure target, JsonContext jsonContext) 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
-
apply
private jakarta.json.JsonStructure apply(jakarta.json.JsonStructure target, jakarta.json.JsonObject operation) Applies a JSON Patch operation to the target.- Parameters:
target- the target to apply the operationoperation- the JSON Patch operation- Returns:
- the target after the patch
-
getPointer
-
getValue
private jakarta.json.JsonValue getValue(jakarta.json.JsonObject operation) -
missingMember
-