Skip to content

How to exclude map key #204

Open
Open

Description

@chagen19

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

  1. yayaryna commented on May 13, 2019

    @yayaryna

    @chagen19 Have you resolved this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions