inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

하얀종이개발자님의 게시글

하얀종이개발자 하얀종이개발자

@noah1209

수강평 작성수
9
평균평점
5.0

게시글 4

질문&답변

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 처리 해주면 될 것 같네요.

좋아요수
0
댓글수
3
조회수
211