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

Anonymous(unnamed) arrays are compared strictly and it not customizable #148

Open
PavelLiakh opened this issue Oct 28, 2021 · 0 comments
Open

Comments

@PavelLiakh
Copy link

JSONAssert v1.5.0

Given

I have JSONs with unnamed arrays inside with differences in autogenerated id field:

___actual: [ { "id": 9901, "value": "foo" }, { "id": 9902, "value": "bar" } ]

expected: [ { "id": 1, "value": "foo" }, { "id": 2, "value": "bar" } ]

When

I comparing them, I want to compare them ignoring the match by the "id" field.

Then

Then comparison fails since JSONAssert tries to 'guess' the key, build map of objects based on the key, and then compare all the keys first.
Keys are guessed in JSONCompareUtil.isUsableAsUniqueKey. The map is built and compared in AbstractComparator.compareJSONArrayOfJsonObjects:
for (Object id : expectedValueMap.keySet()) { if (!actualValueMap.containsKey(id)) { result.missing(formatUniqueKey(key, uniqueKey, id), expectedValueMap.get(id));

Expected
To be able to 'customize' the assertion of such unnamed arrays e.g. by ignoring the fields that are able to be a key.

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