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;
Answer from SQiShER on Stack Overflow
🌐
Javers
javers.org › documentation › diff-examples
Diff Examples — JaVers Documentation
JaVers uses Reflection and captures Person as the item type in the subordinates collection. But when collections are passed as top-level references, for example: ... due to type erasure, there is no way to statically determine the type of items ...
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.

🌐
Netlify
mallim.netlify.app › java-tips-how-to-compare-the-difference-for-two-given-java-objects
Java Tips: How to compare the difference for two given Java objects? | Mallim's Site
September 24, 2020 - JaVers Homepage: https://javers.org/documentation/ Quick intro: https://www.baeldung.com/javers java-object-dff Homepage: http://sqisher.github.io/java-object-diff/ Example 1 : https://morioh.com/p/c98c7721a9ed Example 2 (Chinese) : ...
🌐
javathinking
javathinking.com › blog › is-there-a-java-library-that-can-diff-two-objects
Is There a Java Library That Can Diff Two Objects? Recursive Comparison & Difference Data Structures — javathinking.com
Exclude Unneeded Fields: Use annotations to skip fields (e.g., Javers’ @DiffIgnore, Jackson’s @JsonIgnore). Test Edge Cases: Validate nulls, empty collections, and circular references. Performance: For large objects, prefer Javers (optimized for reflection) over Jackson (serialization overhead). Yes, Java has robust libraries for object diffing!
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
🌐
Baeldung
baeldung.com › home › java › intro to javers
Intro to JaVer | Baeldung
June 27, 2025 - We can compare those two objects using the compare() method from the JaVers class: @Test public void givenPersonObject_whenApplyModificationOnIt_thenShouldDetectChange() { // given Javers javers = JaversBuilder.javers().build(); Person person ...
🌐
Javadoc.io
javadoc.io › static › org.javers › javers-core › 1.5.0 › org › javers › core › diff › Change.html
Change (javers-core 1.5.0 API)
For more information see Diff javadoc. ... Affected domain object (Cdo). Depending on concrete Change type, it could be new Object, removed Object or new version of changed Object. Optional - available only for freshly generated diff. Not available for Changes read from JaversRepository
Find elsewhere
🌐
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%
🌐
Javadoc.io
javadoc.io › static › org.javers › javers-core › 1.5.0 › org › javers › core › Javers.html
Javers (javers-core 1.5.0 API)
JaVers core function, deeply compares two arbitrary complex object graphs. To calculate a diff, just provide two versions of the same Domain Object (Entity or ValueObject) or handles to two versions of the same object graph.
🌐
Reddit
reddit.com › r/programming › object auditing and diff framework for java
r/programming on Reddit: Object auditing and diff framework for Java
July 1, 2017 - Core JaVers module it's very ... for find a diff between two objects · JaVers can record changes to any Java object on every application layer (not only persistence layer)....
🌐
GitHub
github.com › javers › javers
GitHub - javers/javers: JaVers - object auditing and diff framework for Java · GitHub
JaVers is the lightweight Java library for auditing changes in your data. We all use Version Control Systems for source code, so why not use a specialized framework to provide an audit trail of your Java objects (entities, POJO, data objects)?
🌐
Readthedocs
java-object-diff.readthedocs.io
java-object-diff Documentation
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.
🌐
Stack Overflow
stackoverflow.com › questions › 75398071 › create-difference-object-with-javers
java - Create difference object with JaVers - Stack Overflow
Perhaps I'm completely misunderstanding the purpose of JaVers, but I'm struggling here. I got this POJO with a few nested subclasses, and I would like to create a new instance of that object ONLY containing the differences between two other instances, every matching field should stay null in ...
🌐
Javers
javers.org › documentation › diff-configuration
Diff Configuration — JaVers Documentation
There are cases where Javers’ diff algorithm isn’t appropriate, and you need to implement your own comparator for certain types. There are two types of Custom comparators: for Value types, you can register a CustomValueComparator and for Custom types, you register a CustomPropertyComparator . The natural way of providing a comparing strategy for Value classes is overriding the standard Object.equals(Object) method.
🌐
DeepWiki
deepwiki.com › javers › javers › 2.2-object-diffing
Object Diffing | javers/javers | DeepWiki
June 25, 2025 - javers-core/src/test/groovy/org/javers/core/cases/Java21SortedMapShouldBeStillMappedToJaversMapType.groovy · Object Diffing is Javers' core mechanism for comparing two object graphs and identifying the specific changes between them.
🌐
Quora
quora.com › Is-there-a-JAVA-API-class-framework-which-can-compare-two-objects-and-give-the-differences-between-them
Is there a JAVA API class (framework) which can compare two objects and give the differences between them? - Quora
Answer (1 of 3): Faced similar issue in one of the project I was working on. Technology stack consisted of Hibernate. There was need to provide audit feature on some of the domain objects and to show diff between consecutive version of the audit records. The solution used was Envers framework(Hib...
🌐
Medium
medium.com › @keremsirm › javers-for-diff-in-java-6062251e23a2
JAVERS FOR DIFF IN JAVA. TAV Technologies | by KEREM SIRMA | Medium
July 24, 2022 - This library helps programmers examine and detect changes in the states of simple Java objects. When we use mutable objects in our code, every object can potentially be modified in various places in the application; JaVers would help us discover and audit these changes. To get started let us add the javers-core Maven dependency to our pom.xml: <dependency><groupId>org.javers</groupId><artifactId>javers-core</artifactId><version>6.6.5</version></dependency> The @DiffInclude annotation should be added to the beginning of the elements in the class that we want to see change.
🌐
YouTube
youtube.com › retarget common
#24. |Rest Assured Framework | Find Difference Between 2 POJO Objects | Javers| Response Assertion - YouTube
#restassured #apitesting #tester #testing #equalshashcode #java #automationtestiingJavers library is a better way to find the difference between two POJO obj...
Published: March 18, 2023
Views: 1K