Class JsonDiff
java.lang.Object
cloud.opencode.base.json.diff.JsonDiff
JSON Diff - JSON Document Comparison Tool
JSON Diff - JSON 文档比较工具
This class compares two JSON documents and generates a detailed difference report. It can also produce JSON Patch (RFC 6902) output.
此类比较两个 JSON 文档并生成详细的差异报告。 它还可以生成 JSON Patch(RFC 6902)输出。
Example | 示例:
JsonNode source = OpenJson.parse("{\"name\":\"John\",\"age\":30}");
JsonNode target = OpenJson.parse("{\"name\":\"Jane\",\"email\":\"jane@example.com\"}");
DiffResult result = JsonDiff.diff(source, target);
// Iterate differences
for (Difference diff : result.getDifferences()) {
System.out.println(diff.getType() + " at " + diff.getPath());
}
// Generate JSON Patch
JsonPatch patch = result.toPatch();
Features | 主要功能:
- Deep comparison of JSON documents - JSON文档的深度比较
- Categorized differences (added, removed, changed, type changed) - 分类差异
- Automatic JSON Patch (RFC 6902) generation from diff - 从差异自动生成JSON Patch
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: N/A - 空值安全: 不适用
- Since:
- JDK 25, opencode-base-json V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents a single difference between documents.static final recordResult of comparing two JSON documents.static enumType of difference 差异类型 -
Method Summary
-
Method Details
-
diff
-
equals
-