You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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));
}
Activity
yayaryna commentedon May 13, 2019
@chagen19 Have you resolved this issue?