Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to use CustomComparator for a object in list #492

skarian92 opened this issue Jan 18, 2017 · 3 comments

Not able to use CustomComparator for a object in list #492

skarian92 opened this issue Jan 18, 2017 · 3 comments


Copy link


I want to compare two objects(of type Sample2) which have one list member of a custom object(of type sample). I wrote custom comparator for Sample class but javers code never hits the custom comparator.

For eg:

public class Sample {

  private String one;

  private final int two;

  public Sample(String one, int two) { = one;
    this.two = two;
public class Sample2 {
  String id;
private List sample;

  public Sample2(String id, List sample) { = id;
    this.sample = sample;


public class CustomSampleComparator implements CustomPropertyComparator {

  public ValueChange compare(Sample left, Sample right, GlobalId affectedId, Property property) {
    System.out.println("Comparator called...");
    return new ValueChange(affectedId, "testing", 3, 6);


Main class:

public class App {
  public static void main(String[] args) {

    Sample type1 = new Sample("34", 54);
    Sample type2 = new Sample("55", 89);

    List samples1 = new ArrayList();

    Sample type3 = new Sample("34", 4);
    Sample type4 = new Sample("55", 9);

    List samples2 = new ArrayList();

    Sample2 sam = new Sample2("1", samples1);
    Sample2 sam2 = new Sample2("1", samples2);

    Javers javers =
        JaversBuilder.javers().registerCustomComparator(new CustomSampleComparator(), Sample.class)

    Diff diff =, sam2);
    System.out.println("Hello World!");

Problem: My custom comparator is never bieng hit.

Copy link

For now, CustomPropertyComparator compares only property values and not items inside collections. We need to check if it possible to use it as a collections Comparator.

@akrystian akrystian self-assigned this Jan 26, 2017
@akrystian akrystian removed their assignment Feb 10, 2017
@pszymczyk pszymczyk self-assigned this Jun 4, 2017
Copy link

fixed in release 3.3.0, see

Copy link

for example :

 javersBuilder.registerValue(BigDecimal.class, (a,b) -> a.compareTo(b) == 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

4 participants