It looks that javers doesn't handle properly comparing generic types in value objects?

356 views Asked by At

What can be done to make javers treat token types as value objects and compare such objects property by property? It looks that ValueChangeAppender is used to compare such objects and it eventually delegates comparison to Objects.equals, which in case equal is not implemented leads to undesirable result.

To make things a little bit clearer I would like javers to satisfy below assertion:

    public static void main(String[] args) {
            Javers javers = JaversBuilder.javers().build();
            Ob<Field> o1 = new Ob<>(new Field("A"));
            Ob<Field> o2 = new Ob<>(new Field("A"));
            Diff diff = javers.compare(o1, o2);
            assertThat(diff.hasChanges(), is(false));
        }

        public static class Ob<T> {
            private final T field;

            public Ob(T field) {
                this.field = field;
            }
        }

        public static class Field {
            private final String something;

            public Field(String something) {
                this.something = something;
            }
        }

Any ideas, how should I approach such a scenario? Is javers capable to satisfy above assertion?

1

There are 1 answers

1
Bartek Walacik On

Token type can be anything, in runtime it's nothing more than Object.class, if you can suggest better strategy for comparing two instances of Object.class (better than calling Object.equals()) please share.