|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object foodev.jsondiff.JsonPatch
public class JsonPatch
Patch tool for differences as produced by JsonDiff.diff(String, String)
.
The patch is a JSON object where members order is not defined, however when applying the patch order matters when editing arrays. Therefore all deletions are done before additions, and more specifically for array deletions the order is reverse.
Syntax:
{
"key": "replaced", // added or replacing key
"~key": "replaced", // added or replacing key (~ doesn't matter for primitive data types)
"key": null, // added or replacing key with null.
"~key": null, // added or replacing key with null (~ doesn't matter for null)
"-key": 0 // key removed (value is ignored)
"key": { "sub": "replaced" } // whole object "key" replaced
"~key": { "sub": "merged" } // key "sub" merged into object "key", rest of object untouched
"key": [ "replaced" ] // whole array added/replaced
"~key": [ "replaced" ] // whole array added/replaced (~ doesn't matter for whole array)
"key[4]": { "sub": "replaced" } // object replacing element 4, rest of array untouched
"~key[4]": { "sub": "merged"} // merging object at element 4, rest of array untouched
"key[+4]": { "sub": "array add"} // object added after 3 becoming the new 4 (current 4 pushed right)
"~key[+4]":{ "sub": "array add"} // ERROR (nonsense)
"-key[4]: 0 // removing element 4 current 5 becoming new 4 (value is ignored)
"-key[+4]: 0 // ERROR (nonsense)
}
Instruction order is merge, set, insert, delete. This is important when altering arrays, since insertions will affect the array index of subsequent delete instructions.
Constructor Summary | |
---|---|
JsonPatch()
|
Method Summary | |
---|---|
static void |
apply(Object orig,
Object patch)
Patches the first argument with the second. |
static String |
apply(String orig,
String patch)
Modifies the given original JSON object using the instructions provided and returns the result. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JsonPatch()
Method Detail |
---|
public static String apply(String orig, String patch) throws IllegalArgumentException
orig
- The original JSON object to modify.patch
- The set of instructions to use.
IllegalArgumentException
- if the given arguments are not accepted.
JsonWrapperException
- if the strings can't be parsed as JSON.public static void apply(Object orig, Object patch)
JsonObject
or (if jar is provided) a Jackson
style ObjectNode
.
orig
- Object to patch. One of JsonObject
or ObjectNode
(if jar available).patch
- Object holding patch instructions. One of JsonObject
or ObjectNode
(if jar available).
IllegalArgumentException
- if the given arguments are not accepted.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |