Framework/Spring Boot
[Error] com.fasterxml.jackson.databind.exc.InvalidDefinitionException
잔망루피
2023. 2. 1. 19:30
⭐ 상황
@Builder
public class CommentResponse {
private String id;
private String username;
private String content;
private Like like;
private Instant createdAt;
}
List<CommentResponse> responseList = commentRepository.findAllByPostId(post_id).stream()
.map(comment -> CommentResponse.builder()
.id(comment.getId())
.username(comment.getUsername())
.content(comment.getContent())
.like(comment.getLike())
.createdAt(comment.getCreatedAt())
.build())
.collect(Collectors.toList());
Comment 객체를 DTO인 CommentResponse로 변환하는 코드
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.postservice.dto.response.CommentResponse and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.postservice.dto.response.Response["result"]->java.util.ArrayList[0])
CommentResponse의 필드가 다 private로 설정되어있다.
접근 할 수 없으니까 문제가 생긴다.
⭐ 해결
DTO에 lombok의 @Getter, @Setter 어노테이션을 추가했다.
참고 👇
https://steady-hello.tistory.com/90
반응형