- java.lang.Object
-
- org.eclipse.parsson.JsonPatchImpl
-
- All Implemented Interfaces:
JsonPatch
public class JsonPatchImpl extends Object implements JsonPatch
This class is an immutable representation of a JSON Patch as specified in RFC 6902.A
The following illustrates both approaches.JsonPatchcan be instantiated withJson.createPatch(JsonArray)by specifying the patch operations in a JSON Patch. Alternately, it can also be constructed with aJsonPatchBuilder.1. Construct a JsonPatch with a JSON Patch.
2. Construct a JsonPatch with JsonPatchBuilder.JsonArray contacts = ... // The target to be patched JsonArray patch = ... ; // JSON Patch JsonPatch jsonpatch = Json.createPatch(patch); JsonArray result = jsonpatch.apply(contacts);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 jakarta.json.JsonPatch
JsonPatch.Operation
-
-
Constructor Summary
Constructors Constructor Description JsonPatchImpl(JsonArray patch, org.eclipse.parsson.JsonContext jsonContext)Constructs a JsonPatchImpl
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonStructureapply(JsonStructure target)Applies the patch operations to the specifiedtarget.booleanequals(Object obj)Compares thisJsonPatchImplwith another object.inthashCode()Returns the hash code value for thisJsonPatchImpl.JsonArraytoJsonArray()Returns theJsonPatchasJsonArray.StringtoString()Returns the JSON Patch text
-
-
-
Constructor Detail
-
JsonPatchImpl
public JsonPatchImpl(JsonArray patch, org.eclipse.parsson.JsonContext jsonContext)
Constructs a JsonPatchImpl- Parameters:
patch- the JSON Patch
-
-
Method Detail
-
equals
public boolean equals(Object obj)
Compares thisJsonPatchImplwith another object.
-
hashCode
public int hashCode()
Returns the hash code value for thisJsonPatchImpl.
-
toString
public String toString()
Returns the JSON Patch text
-
apply
public JsonStructure apply(JsonStructure target)
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
public JsonArray toJsonArray()
Description copied from interface:JsonPatchReturns theJsonPatchasJsonArray.- Specified by:
toJsonArrayin interfaceJsonPatch- Returns:
- this
JsonPatchasJsonArray
-
-