본문 바로가기
ErrorRecord

[Error Record] org.springframework.http.converter.HttpMessageConversionException

by jinjin98 2022. 12. 5.

org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class 클래스명]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `클래스명` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 2]

 

스프링 부트로 Rest API 테스트를 할 때 발견한 에러입니다.

TestRestTeamplate 클래스의 xxForObject() 메서드로 반환받을 DTO 클래스에 기본 생성자가 없을 때 발생합니다.

Lombok(롬복) 의 @NoargsConstructor 를 이용하거나, 직접 기본 생성자를 작성해 해결할 수 있습니다.

댓글