No converter found for return value of type: class java.util.HashMap 문제
- 작성자 :
- 정*우
- 작성일 :
- 2023-11-08 14:57:46
- 조회수 :
- 1,387
- 구분 :
- 공통컴포넌트
- 진행상태 :
- 완료
Q
ajax로 controller 요청하여 return 값을 json으로 받을때 아래와 같은 오류가 납니다. jackson-core 관련 dependency를 pom.xml에 추가 하라는 이야기가 많아
해당 내용도 추가 하였으나 계속 에러가 나는 상태입니다.
* 오류내용
java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.HashMap
* controller 소스 부분
@PostMapping("/file/upload.do")
@ResponseBody
public Map<String,Object> uploadFiles(
MultipartFile[] uploadFiles
,@RequestParam(value="module_path",required=false, defaultValue="")String module_path
,@RequestParam(value="atch_file_id",required=false, defaultValue="")String atch_file_id
,@RequestParam(value="target_image_tag",required=false, defaultValue="")String target_image_tag
) throws IOException{
Map<String,Object> result=new HashMap<String,Object>();
result.put("code","error");
result.put("codeDetail","필수값이 입력되지 않았습니다.");
return result;
}
* pom.xml dependency
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.2</version>
</dependency>
해당 내용도 추가 하였으나 계속 에러가 나는 상태입니다.
* 오류내용
java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.HashMap
* controller 소스 부분
@PostMapping("/file/upload.do")
@ResponseBody
public Map<String,Object> uploadFiles(
MultipartFile[] uploadFiles
,@RequestParam(value="module_path",required=false, defaultValue="")String module_path
,@RequestParam(value="atch_file_id",required=false, defaultValue="")String atch_file_id
,@RequestParam(value="target_image_tag",required=false, defaultValue="")String target_image_tag
) throws IOException{
Map<String,Object> result=new HashMap<String,Object>();
result.put("code","error");
result.put("codeDetail","필수값이 입력되지 않았습니다.");
return result;
}
* pom.xml dependency
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.2</version>
</dependency>
환경정보
-
- OS 정보 : WINDOWS10
- 표준프레임워크 버전 : 3.9
- JDK(JRE) 정보 : 1.8
- WAS 정보 : TOMCAT 8.5
- DB 정보 : MARIA
- 기타 환경 정보 :
A
안녕하세요.
표준프레임워크 센터입니다.
기재하신 내용만으로는 정확한 답변이 어렵습니다.
에러 로그를 확인할 수 없어 정확한 원인은 알 수 없으나
다음 서블릿 빈 설정 파일에
/src/main/webapp/WEB-INF/config/egovframework/springmvc/dispatcher-servlet.xml
다음이 추가되었는지 확인해 보시기 바랍니다.
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter ">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" >
<property name="supportedMediaTypes" value="application/json" />
</bean>
</property>
</bean>
다음 Rest 기반 프로젝트를 참고하셔도
도움이 되실듯 합니다.
https://www.egovframe.go.kr/home/sub.do?menuNo=93
감사합니다.
표준프레임워크 센터입니다.
기재하신 내용만으로는 정확한 답변이 어렵습니다.
에러 로그를 확인할 수 없어 정확한 원인은 알 수 없으나
다음 서블릿 빈 설정 파일에
/src/main/webapp/WEB-INF/config/egovframework/springmvc/dispatcher-servlet.xml
다음이 추가되었는지 확인해 보시기 바랍니다.
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter ">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" >
<property name="supportedMediaTypes" value="application/json" />
</bean>
</property>
</bean>
다음 Rest 기반 프로젝트를 참고하셔도
도움이 되실듯 합니다.
https://www.egovframe.go.kr/home/sub.do?menuNo=93
감사합니다.