스프링/오류

org.springframework.http.converter.HttpMessageNotWritableException

째로스 2023. 6. 29. 12:05
@RestController("apiNoticeController")
@RequestMapping("/api/notice/")
public class NoticeController {
	
	@Autowired
	private NoticeService service;
	
	@RequestMapping("list")
	public List<Notice> list() throws ClassNotFoundException, SQLException {
		
		List<Notice> list = service.getList(1, "TITLE", "");
		
		return list;
	}
}

위와 같이 리스트를 반환시켜 해당 객체를 JSON 형식으로 클라이언트에 넘기려 했으나

org.springframework.http.converter.HttpMessageNotWritableException 오류가 발생했다.

 

※ 해결방법

Json 방식으로 타입을 변환시켜주는 Jackson Databind 라이브러리 필요 

pom.xml에 해당 라이브러리를 추가하니 문제가 해결되었다.

 

- Maven Repository  Jackson Databind 라이브러리

https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind