본문 바로가기

낙서장/Spring

Spring Ajax JSON Encoding

Ajax(비동기) 통신 시  response type json으로 받을 때 인코딩 오류가 발생하여 JSON으로 보낼 때 UTF-8 인코딩 설정

 

IOC Container(*.xml)

<!-- spring mvc 어노테이션 -->
	<mvc:annotation-driven>
	<!-- JSON 대한 인코딩 타입 JSON, UTF-8 방식으로 응답설정  -->
		<mvc:message-converters>
			<bean
				class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
				<property name="supportedMediaTypes">
					<list>
						<value>application/json; charset=UTF-8</value>
					</list>
				</property>
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>

pom.xml(maven)

	<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.8.10</version>
		</dependency>

스프링 부트는 기본적으로 org.fasterxml.jackson 사용하고 있다.

스피링 4.1부터는 org.codehaus.jackson(1.8 or 1.9)의 지원을 중단하였다.

jackson-databind 통합? 

'낙서장 > Spring' 카테고리의 다른 글

Spring PDF 파일 ResponseEntity로 보여주기  (0) 2021.09.23
Oracle DataBase PDF파일 값 넣기!!  (0) 2021.09.07
Spring 다른 서버에 파일 보내기(FTP)  (0) 2021.09.07
Spring Project Setting  (0) 2021.08.19
Spring @Scheduled  (0) 2021.08.12