Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.
/ diff Public archive

Allows to diff two arbitrary Java objects and retrieve the diff result as a list of strings.

License

Notifications You must be signed in to change notification settings

codereligion/diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Diff Maven Central Build Status SonarQube Coverage

Allows to diff any two Java objects and retrieve the diff result as a list of strings. The result is a unified diff without any contextual lines.

Requirements

  • Java 1.6 or higher
  • dependencies see maven pom

Example code

    SomeDomainObject base = getPersistedObject();
    SomeDomainObject working = getManipulatedObject();

    Configuration configuration = new Configuration()
        .excludeProperty("someUnwantedPropertyName")
        .useSerializer(new SomeSerializer())
        .useComparator(new SomeComparator())
        .useNaturalOrderingFor(SomeComparable.class)
        .useBaseObjectName("BaseObject")
        .useWorkingObjectName("WorkingObject");
		
    List<String> differences = new Differ(configuration).diff(base, working);

    for (String diff : differences) {
        System.out.println(diff);
    }
	...

Example output

--- BaseObject
+++ WorkingObject
@@ -1,1 +1,4 @@
-SomeDomainObject.someIntegerProperty='21'
+SomeDomainObject.someIntegerProperty='42'
+SomeDomainObject.someIterableProperty[0]='foo'
+SomeDomainObject.someIterableProperty[1]='bar'
+SomeDomainObject.someMapProperty['someMapKey']='someMapValue'
...

For more details have a look at the wiki.

About

Allows to diff two arbitrary Java objects and retrieve the diff result as a list of strings.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages