com.github.fge.jsonpatch.diff
Class JsonDiff

java.lang.Object
  extended by com.github.fge.jsonpatch.diff.JsonDiff

public final class JsonDiff
extends Object

"Reverse" factorizing JSON Patch implementation

This class only has one method, asJson(JsonNode, JsonNode), which takes two JSON values as arguments and returns a patch as a JsonNode. This generated patch can then be used in JsonPatch.fromJson(JsonNode).

Numeric equivalence is respected. Operations are always generated in the following order:

Array values generate operations in the order of elements. Factorizing is done to merge add and remove into move operations and convert duplicate add to copy operations if values are equivalent. No test operations are generated (they don't really make sense for diffs anyway).

Note that due to the way JsonNode is implemented, this class is inherently not thread safe (since JsonNode is mutable). It is therefore the responsibility of the caller to ensure that the calling context is safe (by ensuring, for instance, that only the diff operation has references to the values to be diff'ed).

Since:
1.2

Method Summary
static JsonNode asJson(JsonNode source, JsonNode target)
          Generate a JSON patch for transforming the source node into the target node
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

asJson

public static JsonNode asJson(JsonNode source,
                              JsonNode target)
Generate a JSON patch for transforming the source node into the target node

Parameters:
source - the node to be patched
target - the expected result after applying the patch
Returns:
the patch as a JsonNode