title: Javers Compare Fields with Annotations
body: <p>I have a Java 8/Maven/Spring Boot project. I am using Javers to audit changes in my application however I have a custom annotation I created that is placed above the fields in a class that I want audited if changed. Here's a sample class:</p>
  
  <pre><code>public class Foo {
    @AuditThis
    private final String someString;
    private final int someInt;
    @AuditThis
    private final double someDouble;
    private final long someLong;
    @AuditThis
    private final List&lt;String&gt; someList;
  }
  </code></pre>
  
  <p>When calling <code>javers.compare(foo1, foo2)</code> I want it to only compare the fields with the annotation <code>@AuditThis</code> on top. Therefore, in this case it would only compare the <code>someString</code>, <code>someDouble</code>, <code>someList</code> fields of the <code>Foo</code> object. </p>
  
  <p>I know you can set up a custom comparator so I tried doing something like this:</p>
  
  <pre><code>public class AuditThisComparator implements CustomPropertyComparator&lt;Object, ValueChange&gt; {
     @Override
     public ValueChange compare(final Object left,
                                final Object right,
                                final GlobalId globalId,
                                final Property property) {
         ValueChange change = null;
  
         Field[] leftFields = left.getClass().getDeclaredFields();
         Field[] rightFields = right.getClass().getDeclaredFields();
  
         int upperBound = leftFields.length;
         for (int i = 0; i &lt; upperBound; i++) {
             if (return i &lt; leftFields.length &amp;&amp; leftFields[i].getAnnotation(AuditThis.class) != null) {
                 change = new ValueChange(globalId, property.getName(), left, right);
                 break;
             }
         }
  
         return change;
     }
  }
  </code></pre>
  
  <p>And then register it like so:</p>
  
  <pre><code>Javers javers = JaversBuilder.javers()
                               .registerCustomComparator(new AuditThisComparator(), Object.class)
                               .build();
  </code></pre>
  
  <p>But this custom comparator never gets called when I do <code>.compare()</code>. Any ideas what I'm doing wrong or if there's an easier way to go about this?</p>
  
  <p>I can't use the <code>@DiffIgnore</code> because the custom annotation I made takes in some special arguments the user can specify that we use in our auditing process. </p>