-
Notifications
You must be signed in to change notification settings - Fork 115
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
whenIgnoringPaths doesn't ignore missing paths #182
Comments
Hi, thanks for feedback. The comparison is not symmetric and it seems you have switched expected and actual value. This should work
|
@lukas-krecan Thanks for your response! In my example I would expect the "root.bar" and "missing" paths which do not exist in the actual value to be ignored in this case. Isn't that how it's supposed to work? |
JsonUnit main focus are tests, not comparing two arbitrary JSONs. It's therefore built around the assumption that you have the expected value under control. So it does not make sense to ignore paths from expected value, because if you do not want some part of the JSON in the expected value, you simple do not put it there. |
Okay, got it. In this case, the documentation should be updated, because it says at https://github.com/lukas-krecan/JsonUnit/tree/json-unit-parent-2.6.1#ignorepaths:
If I understood you correctly, Alternatively, would you accept a PR to match the code to the documentation? |
The first sentence clearly states that it applies only to the actual value. I could repeat the words |
Exactly, and Anyway, thanks for your time! |
Ah, I see. I still do not understand why would you put something you want to ignore to the expected value, but I agree that the current behavior might be confusing if you do. |
@lukas-krecan Thanks for re-opening the issue!
In the specific use case we're deserializing a JSON payload using Jackson into a POJO which doesn't map all the keys and check afterwards, if the mapped fields are there when serializing the POJO back into JSON. |
#182 Ignore paths even if present in expected value
Released as 2.6.3 |
@lukas-krecan Thanks a lot! |
Fixed via #184 |
I'm using the AssertJ integration of JsonUnit (
net.javacrumbs.json-unit:json-unit-assertj:2.6.1
) and expectedJsonAssert#whenIgnoringPaths(String ...)
to ignore missing paths/keys as well.The documentation at https://github.com/lukas-krecan/JsonUnit/tree/json-unit-parent-2.6.1#ignorepaths says (emphasize by me):
The following test is failing, though:
The text was updated successfully, but these errors were encountered: