Package com.github.fge.jsonpatch.diff
Class JsonDiff
- java.lang.Object
-
- com.github.fge.jsonpatch.diff.JsonDiff
-
@ParametersAreNonnullByDefault public class JsonDiff extends Object
JSON "diff" implementationThis 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
JsonPatchor as aJsonNode.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
JsonPatchdirectly or, for backwards compatibility, as aJsonNode.- Since:
- 1.2
-
-
Field Summary
Fields Modifier and Type Field Description protected static com.github.fge.msgsimple.bundle.MessageBundleBUNDLEprotected static com.google.common.base.Equivalence<com.fasterxml.jackson.databind.JsonNode>EQUIVALENCEprotected static com.fasterxml.jackson.databind.ObjectMapperMAPPER
-
Constructor Summary
Constructors Modifier Constructor Description protectedJsonDiff()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.databind.JsonNodeasJson(com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)Generate a JSON patch for transforming the source node into the target nodestatic JsonPatchasJsonPatch(com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)Generate a JSON patch for transforming the source node into the target nodeprotected static voidcomputeArray(Map<com.github.fge.jackson.jsonpointer.JsonPointer,com.fasterxml.jackson.databind.JsonNode> ret, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)protected static voidcomputeObject(Map<com.github.fge.jackson.jsonpointer.JsonPointer,com.fasterxml.jackson.databind.JsonNode> ret, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)protected static voidcomputeUnchanged(Map<com.github.fge.jackson.jsonpointer.JsonPointer,com.fasterxml.jackson.databind.JsonNode> ret, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.JsonNode first, com.fasterxml.jackson.databind.JsonNode second)protected static voidgenerateArrayDiffs(DiffProcessor processor, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.node.ArrayNode source, com.fasterxml.jackson.databind.node.ArrayNode target)protected static voidgenerateDiffs(DiffProcessor processor, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)protected static voidgenerateObjectDiffs(DiffProcessor processor, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.node.ObjectNode source, com.fasterxml.jackson.databind.node.ObjectNode target)protected static Map<com.github.fge.jackson.jsonpointer.JsonPointer,com.fasterxml.jackson.databind.JsonNode>getUnchangedValues(com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)
-
-
-
Method Detail
-
asJsonPatch
public static JsonPatch asJsonPatch(com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)
Generate a JSON patch for transforming the source node into the target node- Parameters:
source- the node to be patchedtarget- the expected result after applying the patch- Returns:
- the patch as a
JsonPatch - Since:
- 1.9
-
asJson
public static com.fasterxml.jackson.databind.JsonNode asJson(com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)Generate a JSON patch for transforming the source node into the target node- Parameters:
source- the node to be patchedtarget- the expected result after applying the patch- Returns:
- the patch as a
JsonNode
-
generateDiffs
protected static void generateDiffs(DiffProcessor processor, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)
-
generateObjectDiffs
protected static void generateObjectDiffs(DiffProcessor processor, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.node.ObjectNode source, com.fasterxml.jackson.databind.node.ObjectNode target)
-
generateArrayDiffs
protected static void generateArrayDiffs(DiffProcessor processor, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.node.ArrayNode source, com.fasterxml.jackson.databind.node.ArrayNode target)
- Parameters:
processor-pointer-source-target-
-
getUnchangedValues
protected static Map<com.github.fge.jackson.jsonpointer.JsonPointer,com.fasterxml.jackson.databind.JsonNode> getUnchangedValues(com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)
-
computeUnchanged
protected static void computeUnchanged(Map<com.github.fge.jackson.jsonpointer.JsonPointer,com.fasterxml.jackson.databind.JsonNode> ret, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.JsonNode first, com.fasterxml.jackson.databind.JsonNode second)
-
computeObject
protected static void computeObject(Map<com.github.fge.jackson.jsonpointer.JsonPointer,com.fasterxml.jackson.databind.JsonNode> ret, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)
-
computeArray
protected static void computeArray(Map<com.github.fge.jackson.jsonpointer.JsonPointer,com.fasterxml.jackson.databind.JsonNode> ret, com.github.fge.jackson.jsonpointer.JsonPointer pointer, com.fasterxml.jackson.databind.JsonNode source, com.fasterxml.jackson.databind.JsonNode target)
-
-