⭐ 상황
@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
반응형
'Framework > Spring Boot' 카테고리의 다른 글
WebFlux (0) | 2023.03.13 |
---|---|
Swagger 에러 (0) | 2023.02.15 |
[Error] The propertyClass in JsonTypeDescriptor is null, hence it doesn't know to what Java Object type to map the JSON column value that was read from the database! (0) | 2023.01.26 |
엔티티의 필드 타입으로 JSON 사용하기 (0) | 2023.01.24 |
[Error] Failed to start bean 'documentationPluginsBootstrapper' (0) | 2023.01.21 |