[Spring Test] Cannot construct instance of ... (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) 해결하기
카테고리 없음 2019. 7. 26. 22:17에러
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class com.example.model.City]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.example.model.City` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (PushbackInputStream); line: 2, column: 3]
생성자에 Jackson의 @JsonCreator를 붙여 해결하고 싶겠지만. 결국 문제가 발생할 것이다.
@Data
public class City {
@NonNull
private Long id;
@NonNull
private String name;
@NonNull
private Integer population;
@JsonCreator
public City(Long id, String name, Integer population) {
this.id = id;
this.name = name;
this.population = population;
}
}
아래 org.springframework.web.HttpMediaTypeNotSupportedException 이 발생하게 된다...
최대한 Lombok을 잘 사용하는 것이 좋다.