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

Target type in jsonPath method of MockMvcResultMatchers #23121

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

Comments

@juanmbellini
Copy link

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);
}

fodil-a added a commit to fodil-a/spring-framework that referenced this issue Jun 15, 2019

Target type in jsonPath method of MockMvcResultMatchers
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

This comment has been minimized.

Copy link
Contributor

commented Jun 15, 2019

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

@sbrannen

This comment has been minimized.

Copy link
Member

commented Jun 18, 2019

Superseded by PR #23141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.