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

PrintingVisitor should print only the relevant fields of a CollectionItemElementSelector #220

Open
odisseus opened this issue Mar 16, 2022 · 0 comments

Comments

@odisseus
Copy link

Consider a class A that has a field b of type List<C>. The type C, in turn, has a large number of fields c1, c2, c3,..., but two C objects are considered "same" if their c1 fields are equal (perhaps C is a data object and c1 is its identifier field).

These rules can be implemented by a custom IdentityStrategy like this:

public class SingleFieldIdentityStrategy implements IdentityStrategy
{
	//...
	public boolean equals(final Object working, final Object base)
	{
		return ((C) working).c1 == ((C) base).c1;
	}
	//...
}

However, the diff summary generated by PrintingVisitor for two A objects is often overly long:

Property at path '/b[C [ \ c1 = "id123" \ c2 = "foo" \ c3= "bar" \ c4 = D [ \ d1 = "baz" \ d2 = "quux" \ d3 = E [ \ e1 = "xxx" \ e2 = "yyy" \ ] \ ] \ ]]/c4/d3/e2' has changed from [ yyy ] to [ zzz ]

It is not necessary to print the entire toString representation of the C type (which may include lots of nested objects), if the C object can be matched with its counterpart by a single field.

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

1 participant