com.github.fge.jsonpatch.diff
Class JsonDiff

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

@ParametersAreNonnullByDefault
public final class JsonDiff
extends Object

JSON "diff" implementation

This class generates a JSON Patch (as in, an RFC 6902 JSON Patch) given two JSON values as inputs. The patch can be obtained directly as a JsonPatch or as a JsonNode.

Note: there is no guarantee about the usability of the generated patch for any other source/target combination than the one used to generate the patch.

This class always performs operations in the following order: removals, additions and replacements. It then factors removal/addition pairs into move operations, or copy operations if a common element exists, at the same pointer, in both the source and destination.

You can obtain a diff either as a JsonPatch directly or, for backwards compatibility, as a JsonNode.

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
static JsonPatch asJsonPatch(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

asJsonPatch

public static JsonPatch asJsonPatch(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 JsonPatch
Since:
1.9

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