构建jb
JaversBuilder jb = JaversBuilder.javers().withMappingStyle(MappingStyle.BEAN).withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).withPrettyPrint(true)
然后
log.info(diff.prettyPrint())
给出
1. ListChange{globalId:'fn.dsl.diff.javers.Instance/Folder:{0F1E2D3C-4B5A-6978-8796-A5B4C3D2E1F0}', property:'permissions', containerChanges:[(3).removed:'fn.dsl.diff.javers.Permission {type: 'ALLOW', mask: '135159', GN: 'entos_users_tst@tn.fntst.ru', GT: 'GROUP', source: 'DIRECT', depth: 'THIS_OBJECT_ONLY' }', (2).'fn.dsl.diff.javers.Permission {type: 'ALLOW', mask: '999415', GN: 'entos_admins_tst@tn.fntst.ru', GT: 'GROUP', source: 'DIRECT', depth: 'THIS_OBJECT_ONLY' }' to 'fn.dsl.diff.javers.Permission {type: 'ALLOW', mask: '135159', GN: 'entos_users_tst@tn.fntst.ru', GT: 'GROUP', source: 'DIRECT', depth: 'THIS_OBJECT_ONLY' }']}
,但预计相当格式化。就像在文档中一样 - http://javers.org/documentation/diff-examples/#compare-valueobjects
System.out.println(diff);
//.. shouldDetectBossChange()
Diff:
1. ReferenceChange{
globalId:'org.javers.core.examples.model.Employee/Great Developer',
property:'boss',
oldRef:'org.javers.core.examples.model.Employee/Manager One',
newRef:'org.javers.core.examples.model.Employee/Manager Second'}
2. ListChange{
globalId:'org.javers.core.examples.model.Employee/Manager Second',
property:'subordinates',
containerChanges: [(0).added:'org.javers.core.examples.model.Employee/Great Developer']}
3. ListChange{
globalId:'org.javers.core.examples.model.Employee/Manager One',
property:'subordinates',
containerChanges:[(0).removed:'org.javers.core.examples.model.Employee/Great Developer']}
我做错了什么? 我应该期待文档中显示的漂亮格式还是手动格式化?
答案 0 :(得分:3)
在您所指的文档中,手动添加了换行符。
diff.toString()
和diff.prettyPrint()
(因为它只是别名)
每次更改后都会添加br。
因此,即使具有一系列ElementChanges的ListChange也会打印在一行中。
使用ChangeProcessor 自定义您的差异格式。请参阅SimpleTextChangeLog示例