java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to ~ 관련 정보.
spring 버전을 3.x 번대로 업그레이드를 한 프로젝트가 있는데 jsonArray를 List<VO>로 받아서 사용을 할 때
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to ~ 요 딴 에러가 발생하면 아래와 같이
처리를 해주면 되더라는...
구글링 결과 spring3.x 버전의 버그 때문 이라는 말도 있는데 흠...
아무튼 object mapper로 convertValue 처리를 해주어야 한다고 한다.
@Override
public JSONObject saveAuthList(List<AuthVO> jsondata) throws Exception {
JSONObject responseJson = new JSONObject();
ObjectMapper mapper = new ObjectMapper();
try {
if(jsondata != null && !jsondata.isEmpty()) {
List<AuthVO> convertedList = mapper.convertValue(jsondata, new TypeReference<List<AuthVO>>(){});
for(AuthVO authVO : convertedList) {
if(authVO.getUa_authtype() == 0) {
// Delete
mposDao.deleteMenu(authVO);
} else {
// Save
mposDao.saveInsertAuthInfo(authVO);
}
}
responseJson.put("msg", "권한 설정을 저장하였습니다.");
}
} catch (Exception e) {
responseJson.put("msg", "권한 설정 중 오류가 발생하였습니다.");
e.printStackTrace();
}
return responseJson;
}
ObjectMapper mapper = new ObjectMapper(); 를 명시하고,
LIST <AuthVO>로 받은 json객체를 아래와 같이 변환.
List <AuthVO> convertedList = mapper.convertValue(jsondata, new TypeReference <List <AuthVO>>(){});
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.testing.models.Account
I'm getting below error: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.testing.models.Account with below code final int expectedId = 1; Test newTest = create(); int
stackoverflow.com