-
Couldn't load subscription status.
- Fork 38.8k
Description
Sam Brannen opened SPR-13351 and commented
Status Quo
In JsonPathExpectationsHelper, the exists() method asserts that the evaluated JsonPath expression results in a value; however, if the value is an array the exists() method throws an AssertionError if the array exists but is empty. Similarly, the doesNotExist() method does not throw an AssertionError if an array exists but is empty.
This specialized treatment for arrays is illogical and inconsistent with the treatment of empty strings and empty maps.
Analysis
It turns out that existing specialized treatment of arrays is a result of the fact that the JsonPath library always returns an empty array if the path is an indefinite path that does not evaluate to a specific result. This can be the case when a JsonPath expression uses a filter to select results based on a predicate for which there is no match in the content. Consult the discussion on what is returned when in the JsonPath documentation for details.
Deliverables
- Ensure that empty arrays are considered existent when the JsonPath is definite but nonexistent when the JsonPath is indefinite, in line with current support for empty strings and empty maps.
- Introduce a new mechanism for asserting that an array, map, or string is empty.
Affects: 3.2 GA
Issue Links:
- Introduce JsonPath matchers for empty and non-empty content [SPR-13352] #17936 Introduce JsonPath matchers for empty and non-empty content ("is depended on by")
- Introduce additional JsonPath matchers in Spring MVC Test [SPR-13320] #17905 Introduce additional JsonPath matchers in Spring MVC Test
Referenced from: commits 07bb037