首页 > 解决方案 > 是否支持使用 java 库“javers”比较功能对 SortedSet 进行更改?

问题描述

具有 SortedSet 类型字段的类不会显示在更改中。

class TestClass{
    String id;
    Set<String> set;
    SortedSet<String> sortedSet;
}

private void runTest(){
        Javers javers = JaversBuilder
                .javers()
                .withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE)
                .registerEntity(new EntityDefinition(TestClass.class, "id"))
                .build();

        TestClass tc1 = new TestClass();
        tc1.id = "1";
        tc1.set = new HashSet<>(Collections.singletonList("StringInSet1"));
        tc1.sortedSet = new TreeSet<>(Collections.singletonList("StringInSortedSet1"));


        TestClass tc2 = new TestClass();
        tc2.id = "1";
        tc2.set = new HashSet<>(Collections.singletonList("StringInSet2"));
        tc2.sortedSet = new TreeSet<>(Collections.singletonList("StringInSortedSet2"));

        Diff diff = javers.compare(tc1, tc2);
        System.out.println(diff.changesSummary());
    }

实际结果:更改 - SetChange:1 预期结果:更改 - SetChange:2

标签: javajavers

解决方案


在https://github.com/javers/javers/issues/888中修复:

修复了当属性类型是基本可枚举类型(例如,SortedMap、SortedSet 等)的子类型时生成更改的回归


推荐阅读