Skip to content

WebTestClient does not provide Hamcrest Matcher assertions for JSONPath [SPR-16729] #21270

@spring-projects-issues

Description

@spring-projects-issues

Eric Deandrea opened SPR-16729 and commented

Seems that the reactive WebTestClient is missing some valuable assertions that are available on MockMvc.

With MockMvc I can do things like

this.mockMvc.perform(get("/some/url"))
  .andExpect(jsonPath("$.someNestedObject.*", Matchers.hasSize(5)))
  .andExpect(jsonPath("$.someNestedObject.anotherObject").value(Matchers.startsWith("Some String")));

The WebTestClient.jsonPath method doesn't have an overloaded

jsonPath(String expression, Matcher<T> matcher)

method like its MockMvcResultMatchers counterpart does. Also JsonPathAssertions doesn't have an overloaded

value(Matcher<T> matcher)

method like its JsonPathResultMatchers counterpart does. Under the covers both JsonPathResultMatchers & JsonPathAssertions utilize the exact same JsonPathExpectationsHelper which exposes the

public <T> void assertValue(String content, Matcher<T> matcher)

method which is needed.

Is there a particular reason this is missing or is it an oversight? Also seems that there is 0 support for assertions against XML using WebTestClient. Again, is there a specific reason as to why not?


Affects: 5.0.5

Issue Links:

Referenced from: commits 20de500

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions