2017-01-23 75 views
0

我在JUnit Test中使用MvcResult類...如何獲取返回的對象?從MvcResult對象獲取響應

MvcResult r = this.mockMvc.perform(get("/aaaa?page=1&size=1&status=aaa").accept(MediaType.APPLICATION_JSON)) 
      .andExpect(status().isOk()) 
      .andReturn(); 



MockHttpServletResponse response = r.getResponse(); 

回答

1

您可以Gson

gson = new GsonBuilder() 
       .disableHtmlEscaping() 
       .create(); 

它轉換爲Object和:

Obj ob = gson.fromJson(jsonString, new TypeToken<Obj>().getType()); 
相關問題