spring web은 기본적으로 jackson 사용
@GetMapping("/jsonMessage")
public Person jsonMessage(@RequestBody Person person) {
return person;
}
@Test
public void jsonMessage() throws Exception {
Person person = new Person();
person.setId(0L);
person.setName("cmlee");
String jsonString = objectMapper.writeValueAsString(person);
this.mockMvc.perform(get("/jsonMessage")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.accept(MediaType.APPLICATION_JSON_UTF8)
.content(jsonString))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(0))
.andExpect(jsonPath("$.name").value("cmlee"));
}
헤더가 중요하다.