You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JsonPathExpectationsHelper's doesNotExist method does not distinguish between the value being null because the jsonPath didn't find a property or because there was an explicit null in the json.
In doesNotExist, if the field/property in the jsonPath isn't there, it eats the AssertionError and returns (as I would expect). If, however, the json has an explicit null for the jsonPath, the doesNotExist falls through to the else statement on line 207 and will fall through without throwing an AssertionError (because the value is null).
If this is a bug in the doesNotExist method, change this ticket to bug/defect instead of feature. If, however, that is not the intent of the doesNotExist method, I would like to have a method that allows me to not only check that there isn't a value in the supplied jsonPath, but also that the field doesn't exist (for jsonPath("$.abc").doesNotExist(), I would want "{\"abc\": null}" to throw an AssertionError and "{}" to pass).
If implementing this feature, be careful not to break empty array behavior mentioned in #17935.
It's certainly not a bug since the code explicitly deals with null, and also the Javadoc talks about "non-null" values (on the exists method). I can see the ambiguity the method name can cause. It's really referring to the existence of a (non-null) value, so it could have been named assertValueExists/assertValueDoesNotExist.
What you're describing sounds more like a check for the existence of a field. We can add an extra pair of methods along the lines of hasJsonPath/hasNoJsonPath.
Uh oh!
There was an error while loading. Please reload this page.
John Ryan Bard opened SPR-16339 and commented
JsonPathExpectationsHelper's doesNotExist method does not distinguish between the value being null because the jsonPath didn't find a property or because there was an explicit null in the json.
In doesNotExist, if the field/property in the jsonPath isn't there, it eats the AssertionError and returns (as I would expect). If, however, the json has an explicit null for the jsonPath, the doesNotExist falls through to the else statement on line 207 and will fall through without throwing an AssertionError (because the value is null).
If this is a bug in the doesNotExist method, change this ticket to bug/defect instead of feature. If, however, that is not the intent of the doesNotExist method, I would like to have a method that allows me to not only check that there isn't a value in the supplied jsonPath, but also that the field doesn't exist (for
jsonPath("$.abc").doesNotExist()
, I would want"{\"abc\": null}"
to throw an AssertionError and"{}"
to pass).If implementing this feature, be careful not to break empty array behavior mentioned in #17935.
Jayway JsonPath has the JsonPathMatchers.hasNoJsonPath / WithoutJsonPath matcher for this.
Test case:
No further details from SPR-16339
The text was updated successfully, but these errors were encountered: