🌐
GitHub
github.com › SQiShER › java-object-diff
GitHub - SQiShER/java-object-diff: Library to diff and merge Java objects with ease · GitHub
java-object-diff is a simple, yet powerful library to find differences between Java objects. It takes two objects and generates a tree structure that represents any differences between the objects and their children.
Starred by 970 users
Forked by 176 users
Languages: Java 53.4% | Groovy 46.6%
🌐
GitHub
github.com › SQiShER › java-object-diff › blob › master › README.md
java-object-diff/README.md at master · SQiShER/java-object-diff
`java-object-diff` is a simple, yet powerful library to find differences between Java objects. It takes two objects and generates a tree structure that represents any differences between the objects and their children.
Author: SQiShER
🌐
Sqisher
sqisher.github.io › java-object-diff
java-object-diff by SQiShER
java-object-diff is a simple, yet powerful library to find differences between Java objects. It takes two objects and generates a tree structure that represents any differences between the objects and their children.
🌐
GitHub
github.com › SQiShER › java-object-diff › blob › master › docs › getting-started.md
java-object-diff/docs/getting-started.md at master · SQiShER/java-object-diff
Library to diff and merge Java objects with ease. Contribute to SQiShER/java-object-diff development by creating an account on GitHub.
Author: SQiShER
🌐
GitHub
github.com › openrewrite › java-object-diff
GitHub - openrewrite/java-object-diff: Library to diff and merge Java objects with ease · GitHub
java-object-diff is a simple, yet powerful library to find differences between Java objects. It takes two objects and generates a tree structure that represents any differences between the objects and their children.
Author: openrewrite
🌐
GitHub
github.com › SQiShER › java-object-diff › blob › master › docs › user-guide.md
java-object-diff/docs/user-guide.md at master · SQiShER/java-object-diff
Library to diff and merge Java objects with ease. Contribute to SQiShER/java-object-diff development by creating an account on GitHub.
Author: SQiShER
🌐
GitHub
github.com › SQiShER › java-object-diff › releases
Releases · SQiShER/java-object-diff
Library to diff and merge Java objects with ease. Contribute to SQiShER/java-object-diff development by creating an account on GitHub.
Author: SQiShER
🌐
GitHub
github.com › SQiShER › java-object-diff › wiki › Getting-Started
Getting Started · SQiShER/java-object-diff Wiki · GitHub
Library to diff and merge Java objects with ease. Contribute to SQiShER/java-object-diff development by creating an account on GitHub.
Author: SQiShER
Find elsewhere
🌐
GitHub
github.com › SQiShER › java-object-diff › wiki
Home · SQiShER/java-object-diff Wiki · GitHub
Library to diff and merge Java objects with ease. Contribute to SQiShER/java-object-diff development by creating an account on GitHub.
Author: SQiShER
Top answer
1 of 8
56

Might be a little late, but I was in the same situation like you and ended up creating my own library for exactly your use-case. Since I was forced to come up with a solution myself, I decided to release it on Github, to spare others the hard work. You can find it here: https://github.com/SQiShER/java-object-diff

--- Edit ---

Here is a little usage example based on the OPs code:

SomeClass a = new SomeClass();
SomeClass b = new SomeClass();

a.setProp1("A");
a.setProp2("X");

b.setProp1("B");
b.setProp2("X");

DiffNode diff = ObjectDifferBuilder.buildDefault().compare(a, b);

assert diff.hasChanges();
assert diff.childCount() == 1;
assert diff.getChild('prop1').getState() == DiffNode.State.CHANGED;
2 of 8
54

http://javers.org is library that does exacly what you need: has methods like compare(Object leftGraph, Object rightGraph) returning the Diff object. Diff contains a list of changes (ReferenceChange, ValueChange, PropertyChange) e.g.

given:
DummyUser user =  dummyUser("id").withSex(FEMALE).build();
DummyUser user2 = dummyUser("id").withSex(MALE).build();
Javers javers = JaversTestBuilder.newInstance()

when:
Diff diff = javers.compare(user, user2)

then:
diff.changes.size() == 1
ValueChange change = diff.changes[0]
change.leftValue == FEMALE
change.rightValue == MALE

It can handle cycles in graphs.

In addition you can get Snapshot of any graph object. Javers has JSON serializers and deserializers to snapshot, and changes so you can easily save them in database. With this library you can easily implement a module for auditing.

🌐
GitHub
github.com › SQiShER › java-object-diff › issues › 42
How to diff Lists? · Issue #42 · SQiShER/java-object-diff
November 12, 2012 - SQiShER / java-object-diff Public · Notifications · You must be signed in to change notification settings · Fork 175 · Star 967 · New issueCopy link · New issueCopy link · Open · Open · How to diff Lists?#42 · Copy link · Labels · difficulty: hardfrequency: highnote: needs documentationtype: question ·
Author: SQiShER
🌐
GitHub
github.com › SQiShER › java-object-diff › blob › master › build.gradle
java-object-diff/build.gradle at master · SQiShER/java-object-diff
Library to diff and merge Java objects with ease. Contribute to SQiShER/java-object-diff development by creating an account on GitHub.
Author: SQiShER
🌐
GitHub
github.com › SQiShER › java-object-diff › issues › 106
SQiShER/java-object-diff
September 30, 2014 - Library to diff and merge Java objects with ease. Contribute to SQiShER/java-object-diff development by creating an account on GitHub.
Author: SQiShER
🌐
GitHub
github.com › SQiShER › java-object-diff › issues
Issues · SQiShER/java-object-diff
Library to diff and merge Java objects with ease. Contribute to SQiShER/java-object-diff development by creating an account on GitHub.
🌐
GitHub
github.com › IvoLimmen › truediff
GitHub - IvoLimmen/truediff: Diff java objects · GitHub
java-object-diff. This is a very nice and feature rich library but it has a bug that is not being fixed.
Author: IvoLimmen