java-object-diff icon indicating copy to clipboard operation
java-object-diff copied to clipboard

Custom NodePath or IdentityStrategy

Open Chumper opened this issue 9 years ago • 5 comments

I want to define a custom IdentityStrategy because all my classes that i compare are based upon one base class. Therefore i thought i can add a custom identity strategy like this:

DiffNode diff = ObjectDifferBuilder.startBuilding()
        .identity()
        .ofCollectionItems(new NodePath().all()).via((working, base) -> {
          if(working instanceof Base && base instanceof Base) {
            return ((Base) working).getId().equals(((Base) base).getId());
          }
          return Objects.isEqual(working, base);
        })

This wont work, because i cant match on all paths to use my strategy. Is there an easy way to define a global IdentityStrategy?

Chumper avatar May 11 '16 17:05 Chumper

Hey, sorry for keeping you waiting so long. I've created a little pull request to help you with your use-case. Can you take a look at #168 and let me know if that helps?

SQiShER avatar Jul 24 '16 15:07 SQiShER

Hey, i replied a few weeks in the PR but just to let you know, that is what I was looking for, good to merge.

Chumper avatar Oct 18 '16 13:10 Chumper

This would also match one of my use cases very nicely, +1 for this

jlsalmon avatar Oct 27 '16 15:10 jlsalmon

Hey guys, sorry for my recent lack of activity. I just have too much on my plate these days. I'll try to free an hour on the weekend to merge this, put out a new release and reply to some questions.

SQiShER avatar Oct 27 '16 20:10 SQiShER

No worries, what you've done already with this library is awesome :)

jlsalmon avatar Oct 28 '16 07:10 jlsalmon