|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.github.fge.jsonpatch.JsonPatch
public final class JsonPatch
Implementation of JSON Patch
JSON Patch, as its name implies, is an IETF draft describing a mechanism to apply a patch to any JSON value. This implementation covers all operations according to the specification; however, there are some subtle differences with regards to some operations which are covered in these operations' respective documentation.
An example of a JSON Patch is as follows:
[ { "op": "add", "path": "/-", "value": { "productId": 19, "name": "Duvel", "type": "beer" } } ]
This patch contains a single operation which adds an item at the end of an array. A JSON Patch can contain more than one operation; in this case, all operations are applied to the input JSON value in their order of appearance, until all operations are applied or an error condition is encountered.
The main point where this implementation differs from the specification is initial JSON parsing. The draft says:
Operation objects MUST have exactly one "op" member
and:
Additionally, operation objects MUST have exactly one "path" member.
However, obeying these to the letter forces constraints on the JSON parser. Here, these constraints are not enforced, which means:
[ { "op": "add", "op": "remove", "path": "/x" } ]
is parsed (as a remove
operation, since it appears last).
IMPORTANT NOTE: the JSON Patch is supposed to be VALID when the
constructor for this class (fromJson(JsonNode)
is used.
Method Summary | |
---|---|
JsonNode |
apply(JsonNode node)
Apply this patch to a JSON value |
static JsonPatch |
fromJson(JsonNode node)
Static factory method to build a JSON Patch out of a JSON representation |
void |
serialize(JsonGenerator jgen,
SerializerProvider provider)
|
void |
serializeWithType(JsonGenerator jgen,
SerializerProvider provider,
TypeSerializer typeSer)
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static JsonPatch fromJson(JsonNode node) throws IOException
node
- the JSON representation of the generated JSON Patch
IOException
- input is not a valid JSON patch
NullPointerException
- input is nullpublic JsonNode apply(JsonNode node) throws JsonPatchException
node
- the value to apply the patch to
JsonPatchException
- failed to apply patch
NullPointerException
- input is nullpublic String toString()
toString
in class Object
public void serialize(JsonGenerator jgen, SerializerProvider provider) throws IOException
serialize
in interface JsonSerializable
IOException
public void serializeWithType(JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException
serializeWithType
in interface JsonSerializable
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |