Skip to content

Support generics (and POJO object mapper) for jsonPath ResultMatcher #27486

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
FichteFoll opened this issue Sep 28, 2021 · 1 comment
Closed
Labels
in: test Issues in the test module status: superseded An issue that has been superseded by another

Comments

@FichteFoll
Copy link

FichteFoll commented Sep 28, 2021

Affects: 2.4.1


When asserting JSON content in a MockMvc, the provided MockMvcResultMatchers.jsonPath functions support automatic type deduction or an explicit Class<T> parameter (via #23141), but there is an additional version in JsonPath that supports a TypeRef generic and is not exposed. It would be very useful if it was, especially for containsInAnyOrder assertions of POJOs.

For this purpose, it would furthermore be useful if a POJO mapper was configured since afaics it isn't currently.

JsonPath Documentation

var configuration = Configuration.defaultConfiguration().mappingProvider(new JacksonMappingProvider());
var document = JsonPath.using(configuration).parse(JSON_DOCUMENT);
var typeRef = new TypeRef<List<Book>>() {};
List<String> titles = document.read("$.store.book", typeRef);
@rstoyanchev
Copy link
Contributor

I've created #31651 and #31653 related to this. Given the need to pass a customized Configuration to JSONPath and the static nature of MockMvc, it might not be possible to make this too convenient, but we should be able to address it effectively in WebTestClient, which also works with MockMvc via MockMvcWebTestClient. We'll try and make it possible at least with MockMvc.

@rstoyanchev rstoyanchev closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2023
@rstoyanchev rstoyanchev added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 22, 2023
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
Projects
None yet
Development

No branches or pull requests

3 participants