뷰 템플릿으로 HTML을 생성해서 응답하는 것이 아니라, HTTP API처럼 JSON 데이터를 HTTP 메시지
바디에서 직접 읽거나 쓰는 경우 HTTP 메시지 컨버터를 사용하면 편리하다.
스프링 MVC는 다음의 경우에 HTTP 메시지 컨버터를 적용한다.
적용 순서 :
ByteArrayHttpMessageConverter
👉StringHttpMessageConverter
👉MappingJackson2HttpMessageConverter
ByteArrayHttpMessageConverter
StringHttpMessageConverter
MappingJackson2HttpMessageConverter
content-type: application/json
@RequestMapping
void hello(@RequetsBody String data) {}
👉 StringHttpMessageConverter
컨버터 동작
content-type: application/json
@RequestMapping
void hello(@RequetsBody HelloData data) {}
👉 MappingJackson2HttpMessageConverter
컨버터 동작
content-type: text/html
@RequestMapping
void hello(@RequetsBody HelloData data) {}
클래스 타입이 객체이지만 미디어 타입이 application/json 이 아닌 text/html 이므로
👉 적용 가능한 컨버터 없음