title: How to retrieve data directly from Spring test MvcResult json response?
body: <p>I want to retrieve a value from json response in order to use in the rest of my test case, here's what I'm doing now:</p>
  <pre><code>MvcResult mvcResult = super.mockMvc.perform(get(&quot;url&quot;).accept(MediaType.APPLICATION_JSON).headers(basicAuthHeaders()))
                  .andExpect(status().isOk())
                  .andExpect(jsonPath(&quot;$[0].id&quot;, is(6))).andReturn();
  
  String responseAsString = mvcResult.getResponse().getContentAsString();
  ObjectMapper objectMapper = new ObjectMapper(); // com.fasterxml.jackson.databind.ObjectMapper
  MyResponse myResponse = objectMapper.readValue(responseAsString, MyResponse.class);
  
  if(myResponse.getName().equals(&quot;name&quot;)) {
      //
      //
  }
  </code></pre>
  <p>I'm wondering is there a more elegant way to retrieve a value directly from <code>MvcResult</code> as with the case of <code>jsonPath</code> for matching?</p>