title: How to get ResponseBody of @RestController as object in a MockMvc junit test?
body: <p>I have a simple junit test that verifies the response of a servlet endpoint.</p>
  
  <p>Problem: I want to obtain the response as <em>java object</em> <code>Person</code>, and not as string/json/xml representation.</p>
  
  <p>Is that possible?</p>
  
  <pre><code>@RestController
  public class PersonController {
      @GetMapping("/person")
      public PersonRsp getPerson(int id) {
          //...
          return rsp;
      }   
  }
  
  @RunWith(SpringRunner.class)
  @WebMvcTest(value = PersonController.class)
  public class PersonControllerTest {
      @Autowired
      private MockMvc mvc;
  
      @Test
      public void test() {
          MvcResult rt = mvc.perform(get("/person")
                  .param("id", "123")
                  .andExpect(status().isOk())
                  .andReturn();
  
          //TODO how to cast the result to (Person) p?
      }
  }
  </code></pre>