从1.4.0版本开始,
“PropertyChange现在从Property解耦,从propertyChange到具体属性的引用已替换为propertyName String字段。”
在1.4.0更改后访问Property的另一种方法是什么?我想在媒体资源中访问“looksLikeId”
最佳答案
您可以使用以下代码段进行操作:
ManagedType managedType = (ManagedType)javers.getTypeMapping(Person.class);
Property property = managedType.getProperty(propertyChange.getPropertyName());
完整示例(常规):
def "should extract Property from PropertyChange"(){
given:
def javers = JaversTestBuilder.newInstance()
when:
def diff = javers.compare(new Person('1','bob'), new Person('1','bobby'))
PropertyChange propertyChange = diff.changes[0]
ManagedType managedType = (ManagedType)javers.getTypeMapping(Person)
Property property = managedType.getProperty(propertyChange.propertyName)
then:
property.name == 'name'
!property.looksLikeId()
}
在1.4.1版本中,我将为javers添加便捷的
getProperty()
方法:Property property = javers.getProperty( propertyChange )