Skip to content

JsonPath assertions fail to differentiate between definite and indefinite results in checks for existence [SPR-13351] #17935

@spring-projects-issues

Description

@spring-projects-issues

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

  1. 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.
  2. Introduce a new mechanism for asserting that an array, map, or string is empty.

Affects: 3.2 GA

Issue Links:

Referenced from: commits 07bb037

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions