Javers returns 实体字段类型更改时的不完整差异(继承)

Javers returns incomplete diff when entity field type is changed (inheritance)

Javers returns 使用抽象类型声明实体字段时的不完整差异。

我正在使用 Javers 2.9.2,但也尝试过 5.4.0。我的问题出现在两个版本中。

我有如下模型:

// An entity.
class Entity {

  AbstractType field;
}

abstract class AbstractType {}

// A value object.
class ConcreteA extends AbstractType {

  AnotherEntity entityA;
}

// A value object.
class ConcreteB extends AbstractType {

  AnotherEntity entityB;

  // Other fields are omitted for simplicity.
}

// The class registered as an entity.
class AnotherEntity {

  String uuid;
  String name;
}

我正在注册上面的实体和值对象。

比较以下对象:

AnotherEntity anotherEntity = new AnotherEntity("name");

Entity originalEntity = new Entity();
originalEntity.field = new ConcreteA(anotherEntity);

Entity updatedEntity = new Entity();
updatedEntity.field = new ConcreteB(anotherEntity);

javers.compare(originalEntity, updatedEntity);

我希望 diff 说:

但是,差异显示只有字段 entityA 被删除 (ReferenceChange)。因此,差异中缺少一个字段。

如何获得我的案例的完整差异?

在 5.5.0 中,我们添加了对类型重构的更好支持。 Added/removed 属性被检测到,Javers 为它们计算正确的差异。 每个 PropertyChange 都有新的枚举 — PropertyChangeType 指示 属性 是否为 added/removed:

/**
 * When two objects being compared have different classes,
 * they can have different sets of properties.
 * <br/>
 * When both objects have the same class, all changes have PROPERTY_VALUE_CHANGED type.
 *
 * @since 5.5.0
 */
public enum PropertyChangeType {

    /**
     * When a property of the right object is absent in the left object.
     */
    PROPERTY_ADDED,

    /**
     * When a property of the left object is absent in the right object.
     */
    PROPERTY_REMOVED,

    /**
     * Regular value change &mdash; when a property is present in both objects.
     */
    PROPERTY_VALUE_CHANGED
}

PropertyChangeType也体现在diff.prettyPrint():

Diff diff = javers.compare(originalEntity, updatedEntity)

println diff.prettyPrint()
Diff:
* changes on org.javers.core.cases.Entity/123 :
  - 'field.entityA' property with reference '...AnotherEntity/uuid' removed
  - 'field.entityB' property with reference '...AnotherEntity/uuid' added