title: How to extract value from JSON response when using Spring MockMVC
body: <p>I have an endpoint that accepts a POST request. I want to get the ID of the newly created entity from the JSON response.</p>
  
  <p>Below is a segment of my code where I'm attempting to do that.</p>
  
  <pre><code>mockMvc.perform(post("/api/tracker/jobs/work")
          .contentType(TestUtil.APPLICATION_JSON_UTF8)
          .content(TestUtil.convertObjectToJsonBytes(workRequest)))
          .andExpect(status().isCreated());
  </code></pre>
  
  <p>If I get that ID I'll query the database for the newly created entity and do some assertions like below: </p>
  
  <pre><code>Work work = work service.findWorkById(id);
  
  assertThat(work.getJobItem().getJobItemName()).isEqualTo(workRequest.getJobItem().getJobItemName());
  assertThat(work.getJobItem().getQuantities()).hasSize(workRequest.getQuantities().size());
  assertThat(work.getJobItem().getQuantityPools()).hasSize(workRequest.getQuantities().size());
  </code></pre>