🌐
Maven Repository
mvnrepository.com › artifact › de.danielbechler › java-object-diff
Maven Repository: de.danielbechler » java-object-diff
aar amazon android apache api arm assets build build-system bundle client clojure cloud config cran data database eclipse example extension framework github gradle groovy io ios javascript jvm kotlin library logging maven mobile module npm osgi plugin resources rlang sdk server service spring ...
🌐
Readthedocs
java-object-diff.readthedocs.io › en › latest › maven
Using with Maven - java-object-diff Documentation
<dependency> <groupId>de.danielbechler</groupId> <artifactId>java-object-diff</artifactId> <version>0.95</version> </dependency> That's it! Now you're ready to go! It can take up to 2 hours after the release of a new version until it is actually mirrored to the Maven Central repository.
🌐
GitHub
github.com › SQiShER › java-object-diff
GitHub - SQiShER/java-object-diff: Library to diff and merge Java objects with ease
Provides read and write access to the underlying objects, allowing you not only to extract the changed values but even to apply the diff as a patch · Requires no changes to your existing classes (in most cases) Provides a very flexible ...
Starred by 969 users
Forked by 177 users
Languages   Java 53.4% | Groovy 46.6% | Java 53.4% | Groovy 46.6%
🌐
Maven Central
central.sonatype.com › artifact › de.danielbechler › java-object-diff
java-object-diff - de.danielbechler - Maven Central - Sonatype
<dependency> <groupId>de.danielbechler</groupId> <artifactId>java-object-diff</artifactId> <version>0.95</version> </dependency> ... <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId>de.danielbechler</groupId> <artifactId>java-object-diff</artifactId> <version>0.95</version> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifa
🌐
GitHub
github.com › SQiShER › java-object-diff › blob › master › docs › maven.md
java-object-diff/docs/maven.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
🌐
Maven Repository
mvnrepository.com › artifact › de.danielbechler › java-object-diff › 0.10.2
Maven Repository: de.danielbechler » java-object-diff » 0.10.2
Library to diff and merge Java objects with ease · Note: There is a new version for this artifact · Maven · Gradle · SBT · Mill · Ivy · Grape · Leiningen · Buildr · Scope: compile · test · provided · runtime · Scope: compile · test · provided ·
🌐
Maven Repository
mvnrepository.com › artifact › org.openrewrite.tools › java-object-diff
Maven Repository: org.openrewrite.tools » java-object-diff
aar amazon android apache api arm assets build build-system bundle client clojure cloud config cran data database eclipse example extension framework github gradle groovy io ios javascript jvm kotlin library maven mobile module npm osgi plugin resources rlang sdk server service spring sql starter ...
🌐
Maven Central
central.sonatype.com › artifact › de.danielbechler › java-object-diff › 0.94
de.danielbechler:java-object-diff:0.94 - Maven Central
://travis-ci.org/SQiShER/java-object-diff</url> </ciManagement> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.jdk>1.5</project.jdk> </properties> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${project.jdk}</source> <target>${project.jdk}</target> <encoding>UTF-8</encoding> <compilerId>groovy-eclipse-compiler</compilerId> </configuration> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.9.2-01</version> </dependency> <depen
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.

Find elsewhere
🌐
GitHub
github.com › SQiShER › java-object-diff › blob › master › build.gradle
java-object-diff/build.gradle at master · SQiShER/java-object-diff
repo = 'maven' name = 'java-object-diff' licenses = ['Apache-2.0'] vcsUrl = 'https://github.com/SQiShER/java-object-diff.git' githubRepo = 'SQiShER/java-object-diff' githubReleaseNotesFile = 'README.md' version { name = project.version · released = new Date() vcsTag = rootProject.name + '-' + project.version ·
Author   SQiShER
🌐
Maven Central
repo1.maven.org › maven2 › de › danielbechler › java-object-diff › 0.93.1
Central Repository: de/danielbechler/java-object-diff/0.93.1
../ java-object-diff-0.93.1-javadoc.jar 2016-01-24 15:20 657051 java-object-diff-0.93.1-javadoc.jar.asc 2016-01-24 15:20 475 java-object-diff-0.93.1-javadoc.jar.md5 2016-01-24 15:20 32 java-object-diff-0.93.1-javadoc.jar.md5.asc 2016-01-24 15:20 475 java-object-diff-0.93.1-javadoc.jar.sha1 ...
🌐
Readthedocs
java-object-diff.readthedocs.io
java-object-diff Documentation
Sometimes you need to figure out, how one version of an object differs from another one. One of the simplest solutions that'll cross your mind is most certainly to use reflection to scan the object for fields or getters and use them to compare the values of the different object instances.
🌐
Maven Central
repo.maven.apache.org › maven2 › org › openrewrite › tools › java-object-diff
Central Repository: org/openrewrite/tools/java-object-diff
org/openrewrite/tools/java-object-diff · / 1.0.1/ 2023-02-20 02:36 - maven-metadata.xml 2023-02-20 02:36 344 maven-metadata.xml.md5 2023-02-20 02:36 32 maven-metadata.xml.sha1 2023-02-20 02:36 40 maven-metadata.xml.sha256 2023-02-20 02:36 64 maven-metadata.xml.sha512 2023-02-20 02:36 128
🌐
Sqisher
sqisher.github.io › java-object-diff
java-object-diff by SQiShER
While all this isn't exactly rocket ... the best code is the code you didn't write, this library aims to help you with all things related to diffing and merging of Java objects by providing a robust foundation and a simple, yet powerful API....
🌐
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 = new Person(1, "Michael Program"); Person personAfterModification = new Person(1, "Michael Java"); // when Diff diff = javers.compare(person, personAfterModification); // then ValueChange change = diff.getChangesByType(ValueChange.class).get(0); assertThat(diff.getChanges()).hasSize(1); assertThat(change.getPropertyName()).isEqualTo("name"); assertThat(change.getLeft()).isEqualTo("Michael Program"); assertThat(change.getRight()).isEqualTo("Michael Java"); }
🌐
GitHub
github.com › SQiShER › java-object-diff › blob › master › README.md
java-object-diff/README.md at master · SQiShER/java-object-diff
To learn how to use **Java Object Diff** have a look at the [Getting Started Guide](http://java-object-diff.readthedocs.org/en/latest/getting-started/). · ### Using with Maven · · ```xml · <dependency> <groupId>de.danielbechler</groupId> <artifactId>java-object-diff</artifactId> <version>0.95</version> </dependency> ``` ·
Author   SQiShER
🌐
Readthedocs
java-object-diff.readthedocs.io › en › latest › getting-started
Getting Started - java-object-diff Documentation
In this case it's very simple. The map contains one entry with the same key and different values. So the root object (the map) contains changes. Since only one item has changed, the root node has one child node. That's the node representing the map entry with key "item".
🌐
GitHub
github.com › SQiShER › java-object-diff › blob › master › src › main › java › de › danielbechler › diff › introspection › ObjectDiffProperty.java
java-object-diff/src/main/java/de/danielbechler/diff/introspection/ObjectDiffProperty.java at master · SQiShER/java-object-diff
import de.danielbechler.diff.inclusion.Inclusion; · import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; · /** * Annotation to be used on property getters in order to configure if and how they should be treated during · * object comparison.
Author   SQiShER