Skip to content

Target type in jsonPath method of MockMvcResultMatchers #23121

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

Closed
juanmbellini opened this issue Jun 12, 2019 · 2 comments
Closed

Target type in jsonPath method of MockMvcResultMatchers #23121

juanmbellini opened this issue Jun 12, 2019 · 2 comments
Assignees
Labels
in: test Issues in the test module status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@juanmbellini
Copy link

juanmbellini commented Jun 12, 2019

Affects: 5.0.5


This in an enhancement

In #21129 MockMvcResultMatchers adds the possibility to set the targetType when using jsonPath, but this can only be achieved as in the following code:

jsonPath("$.id").value(is(entity.getId()), Long.class) // getId returns a Long

It would be great to have the following method in the MockMvcResultMatchers class:

<T> jsonPath(String, Matcher<T>, Class<T>) // here you can set the target type in the same method.

See

public static <T> ResultMatcher jsonPath(String expression, Matcher<T> matcher) {

The new method can be something like this:

public static <T> ResultMatcher jsonPath(String expression, Matcher<T> matcher, Class<T> targetType) {
    return new JsonPathResultMatchers(expression).value(matcher, targetType);
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 12, 2019
@sbrannen sbrannen added in: test Issues in the test module type: enhancement A general enhancement labels Jun 14, 2019
fodil-a added a commit to fodil-a/spring-framework that referenced this issue Jun 15, 2019
This introduces an helper method to specify a type to coerce into
for MockMvcResultMatchers.
New signature:
MockMvcResultMatchers#jsonPath(String, Class<T>, Matcher<T>)

Solves spring-projects#23121

Signed-off-by: RustyTheClone <21066051+rustytheclone@users.noreply.github.com>
@fodil-a
Copy link
Contributor

fodil-a commented Jun 15, 2019

Solved in pull-request #23141
I added a method MockMvcResultMatchers#jsonPath(String, Class<T>, Matcher<T>)

@sbrannen sbrannen self-assigned this Jun 18, 2019
@sbrannen sbrannen removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 18, 2019
@sbrannen
Copy link
Member

Superseded by PR #23141

@sbrannen sbrannen added the status: superseded An issue that has been superseded by another label Jun 18, 2019
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 status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants