Issue
I'm using MvcResult
class in JUnit Test.
How can I obtain the object which is returned?
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();
Solution
You can cast it to Object
with Gson
gson = new GsonBuilder()
.disableHtmlEscaping()
.create();
And:
Obj ob = gson.fromJson(jsonString, new TypeToken<Obj>().getType());
Answered By - Alexandru Hodis