Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to exclude map key #204

Open
chagen19 opened this issue Jul 13, 2018 · 1 comment
Open

How to exclude map key #204

chagen19 opened this issue Jul 13, 2018 · 1 comment

Comments

@chagen19
Copy link

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));
}
@yayaryna
Copy link

@chagen19 Have you resolved this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants