-
Notifications
You must be signed in to change notification settings - Fork 177
Open
Description
I'm looking for the correct way to exclude a map key. Below is an example that shows that the lastUpdate field is not being excluded. Any help would be greatly appreciated.
@Test
public void shouldBeEqualWhenObjectsAreNotEqualButFieldIsConfiguredToBeIgnored() {
Map<String, Object> before = new LinkedHashMap<>();
before.put("field1", "value1");
before.put("excludedField", "excludedField value");
Map<String, Object> after = new HashMap<>();
after.put("field1", "value1");
//@formatter:off
DiffNode root = ObjectDifferBuilder
.startBuilding()
.inclusion()
.exclude()
.propertyName("excludedField")
.node(NodePath.with("excludedField"))
.and()
.build()
.compare(after, before);
//@formatter:on
List<Map<String, Object>> results = new ArrayList<>();
DiffNode.Visitor visitor = (node, visit) -> {
if (node.hasChanges() && !node.hasChildren()) {
final Object beforeValue = node.canonicalGet(before);
final Object afterValue = node.canonicalGet(after);
Map<String, Object> changeMap = new HashMap<>();
changeMap.put("state", node.getState().name());
changeMap.put("path", node.getPath().toString());
changeMap.put("beforeValue", beforeValue);
changeMap.put("afterValue", afterValue);
results.add(changeMap);
}
};
root.visit(visitor);
Assert.assertThat(results, hasSize(0));
}
Metadata
Metadata
Assignees
Labels
No labels