Skip to content
Advertisement

Javers – comparison String, Collection and Boolean with defined rules

I have 2 classes:

JavaScript

And also my own defined comparators(rules):

JavaScript

These comparators are defined so that an empty String is treated the same as null, an empty Collection is treated the same as null, and a Boolean false is treated the same as null. In the main method I try to compare 2 objects so as to check if the defined comparators work.

JavaScript

Unfortunately, the comparison does not work as expected. In JaversBuilder I tried add .registerValue(String.class, (a, b) -> StringUtils.equals(a,b)) but it also dont work. Result of print:

JavaScript

What should I change to make it work. If comparators were working correctly In this example, diff would not have any changes

Advertisement

Answer

I think this problem is caused by your assumption that CustomValueComparators can provide some custom logic for nulls. This assumption is sensible but false. Currently, CustomValueComparators always get non-null values to compare. Javers itself deals with nuls.

I have created an issue to manage this https://github.com/javers/javers/issues/1075

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement