Spring 4.1.2 jackson 사용
- 작성자
- 관리자
- 작성일자
- 2017-11-20
- 조회수
- 18,974
Q eGovFrame3.6 버전 스프링 4.1.2에서 jackson(json) 사용 시 에러가 납니다.
A
spring 4.1.x 이상부터 deprecated되어서 data bind로 변경이 필요합니다.
버전 업그레이드에 따른 dependency 이슈 문제 입니다.
1)
- BEFORE
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
-AFTER
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.3</version>
</dependency>
2. context-xxxx.xml(MappingJacksonJsonView가 선언된 xml파일) 에러 아래와 같이 변경
-BEFORE
<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" >
<property name="extractValueFromSingleKeyModel" value="true"/>
</bean>
-AFTER
<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
<property name="contentType" value="text/html;charset=UTF-8"/>
</bean>
버전 업그레이드에 따른 dependency 이슈 문제 입니다.
1)
- BEFORE
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
-AFTER
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.3</version>
</dependency>
2. context-xxxx.xml(MappingJacksonJsonView가 선언된 xml파일) 에러 아래와 같이 변경
-BEFORE
<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" >
<property name="extractValueFromSingleKeyModel" value="true"/>
</bean>
-AFTER
<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
<property name="contentType" value="text/html;charset=UTF-8"/>
</bean>