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

Comment From: rstoyanchev

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.