inflearn logo
Course

Course

Instructor

noah1209's Posts

noah1209 noah1209

@noah1209

Reviews Written
9
Average Rating
5.0

Posts 1

Q&A

author 배열이 비어서 오는 경우가 있으니 참고하세요.

private SearchResponse createResponse(Document document) { String author = Optional.ofNullable(document.authors()) .filter(authors -> !authors.isEmpty()) .map(List::getFirst) .orElse("Unknown Author"); String publisher = Optional.ofNullable(document.publisher()) .filter(p -> !p.isBlank()) .orElse("Unknown Publisher"); return SearchResponse.builder() .title(document.title()) .author(author) .publisher(publisher) .pubDate(DateUtils.parseOffsetDateTime(document.dateTime()).toLocalDate()) .isbn(document.isbn()) .build(); } 요런식으로 createResponse 부분만 Optional을 이용해서 null 처리 해주면 될 것 같네요.

Likes
0
Comments
3
Viewcount
212