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

Add support for custom diff comparers #23

Open
wbish opened this issue Mar 10, 2018 · 1 comment
Open

Add support for custom diff comparers #23

wbish opened this issue Mar 10, 2018 · 1 comment

Comments

@wbish
Copy link
Owner

wbish commented Mar 10, 2018

A common theme that has been developing is people that want to customize the output of the patch object:

#20 wants to create a compact json patch object where each left value is omitted -- does not care about unpatch functionality.
#21 wants to skip adding to the patch document cases where the same key exists but the value is different. This means edits are not included in the patch document -- only adds and deletes. Essentially wants to see if the structure of the document has changed -- not so much the contents of each key.
#18 seeks to find diff of a subset of the document.

I do not want to change the default behavior of JsonDiffPatch because I think the main value add of the library is to support straightforward diff/patch/unpatch.

However, I think there is a valid case to make for JsonDiffPatch support custom diff comparers that can have user defined behavior.

JsonDiffPatch(Option, IComparer)

I have not thought this through, but the interface might look something like the following:

IComparer

  • handleEdit(path, key, left, right)
  • handleAdd(path, key, right)
  • handleDelete(path, key, left)

This is not really diff patch output formatter as the output would still technically be supported by patch and unpatch -- however, those methods may just have weird behavior if someone implements a strange IComparer.

@joaopgrassi
Copy link

joaopgrassi commented Aug 8, 2018

#20 would be extremely helpful for my use case:

We have a legacy database, and now we built a central tool to manage our configuration data. Problem is that old tools still use the legacy db, so we still need to push data from the new tool to the legacy db for backward compatibility.

What can happen is that someone can go and change some value directly via DB (bad) or our tool is unable to sync the data. Either case, we have mismatched data.

We created a reconciliation process that fetch data from both side and compare it. Later on, we want to produce a report that contains the diff and what didn't match. JsonDiffPatch would be perfect for producing a diff of the data (we already have it in Json format). But, having the whole document doesn't help. When there's an issue, we want to look at the report and easily spot what's not matching.

For small documents it's fine, but that's really not the case on real world apps. Our documents have more than 15 fields plus nested arrays.

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