Skip to content
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

Enhance JsonPathExpectationsHelper to allow use of JSONPath Configuration #31651

Closed
rstoyanchev opened this issue Nov 22, 2023 · 0 comments
Closed
Assignees
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Nov 22, 2023

JSONPath supports using a Configuration to customize its behavior, or to pass a JsonProvider that in turn enables parsing to higher level objects. JsonPathExpectationsHelper manages JSONPath internally without any option to change this, and effectively uses Configuration.defaultConfiguration() that supports parsing to basic types only.

We should open up JsonPathExpectationsHelper to make it possible to pass or customize the Configuration to use, and that would enable decoding to higher level objects. The helper does have a method to read to a target Class but it won't work for anything more than basic types, and we add another that takes ParameterizedTypeReference.

This will not fully address #27486 and #31423 since MockMvc there is no good way to re-use a custom Configuration in a static API. However, it will enable WebTestClient to transparently pass a Configuration to JsonPathExpecationsHelper. It will also make it possible for MockMvc users to create a custom ResultMatcher instance that delegates to JsonPathExpectationsHelper. We can separately explore some such built-in option for MockMvc.

@rstoyanchev rstoyanchev added in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Nov 22, 2023
@rstoyanchev rstoyanchev added this to the 6.2.x milestone Nov 22, 2023
@snicoll snicoll self-assigned this Jan 15, 2024
snicoll added a commit to snicoll/spring-framework that referenced this issue Jan 16, 2024
This commit improves JsonPathExpectationsHelper to allow a custom json
path configuration to be defined. The primary objective of a custom
configuration is to specify a custom mapper that can deserialize complex
object structure.

As part of this commit, it is now possible to invoke a Matcher against
a type that holds generic information, using a regular
ParameterizedTypeReference.

Given that the existing constructor takes a vararg of Object, this
commit also deprecates this constructor in favor of formatting the
expression String upfront.

Closes spring-projectsgh-31651
@snicoll snicoll modified the milestones: 6.2.x, 6.2.0-M1 Jan 16, 2024
snicoll added a commit to snicoll/spring-framework that referenced this issue Jan 31, 2024
This commit improves JsonPathExpectationsHelper to allow a custom json
path configuration to be defined. The primary objective of a custom
configuration is to specify a custom mapper that can deserialize complex
object structure.

As part of this commit, it is now possible to invoke a Matcher against
a type that holds generic information, using a regular
ParameterizedTypeReference.

Given that the existing constructor takes a vararg of Object, this
commit also deprecates this constructor in favor of formatting the
expression String upfront.

Closes spring-projectsgh-31651
@bclozel bclozel changed the title Enhance JsonPathExpectationsHelper to allow use of JSONPath Configuration Enhance JsonPathExpectationsHelper to allow use of JSONPath Configuration Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants