HTTP통신에서 일반 문자열이아닌 JSON이나 XML로 통신하기 위해 사용 ( 주로 Ajax통신 할 때 사용)
Ajax 통신
1. XML로 데이터 주고 받기 : XMLHttpReqeus(내장브라우저)
설정
spring-servlet.xml
<mvc:annotation-driven>
<!-- messageConvertert -->
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html; charset=UTF-8</value> <!-- String에 대해서 인코딩 타입이 UTF-8인 text.html방식으로 응답 -->
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"><!-- 인코딩 타입이 UTF-8이고 JSON으로 응답 -->
<property name="supportedMediaTypes">
<list>
<value>application/json; charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
pom.xml
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.1.1</version>
</dependency>