Package javax.json
Interface JsonPatch
-
public interface JsonPatch
This interface represents an immutable implementation of a JSON Patch as defined by RFC 6902.
This is a near-exact copy of the same-titled Java EE 8 Class:javax.json.JsonPatch
Commenting has been slightly modified to accompany HiLiting the Code Examples.
Java Source Code remains identical to the Sun-Oracle & 'GlassFish' Released Distributions.
Read included License:HERE
, and theCDDL+GPL-1.1
Alljavax.json.*
Code Obtained From:GitHub JavaEE jsonp
Public Archive.
AJsonPatch
can be instantiated withJson.createPatch(JsonArray)
by specifying the patch operations in a JSON Patch. Alternately, it can also be constructed with aJsonPatchBuilder
.
The following illustrates both approaches.
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
- See Also:
- RFC 6902
Hi-Lited Source-Code:This File's Source Code:
- View Here: javax/json/JsonPatch.java
- Open New Browser-Tab: javax/json/JsonPatch.java
File Size: 5,884 Bytes Line Count: 173 '\n' Characters Found
Glass Fish Implementation Class:
- View Here: org/glassfish/json/JsonPatchImpl.java
- Open New Browser-Tab: org/glassfish/json/JsonPatchImpl.java
File Size: 12,814 Bytes Line Count: 332 '\n' Characters Found
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
JsonPatch.Operation
This enum represents the list of valid JSON Patch operations as defined by RFC 6902.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends JsonStructure>
Tapply(T target)
Applies the patch operations to the specifiedtarget
.JsonArray
toJsonArray()
Returns theJsonPatch
asJsonArray
.
-
-
-
Method Detail
-
apply
<T extends JsonStructure> T apply(T target)
Applies the patch operations to the specifiedtarget
. The target is not modified by the patch.- Type Parameters:
T
- the target type, must be a subtype ofJsonStructure
- 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
JsonArray toJsonArray()
Returns theJsonPatch
asJsonArray
.- Returns:
- this
JsonPatch
asJsonArray
-
-