Skip to content

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

Description

@odisseus

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.

Activity

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