안녕하세요.!!
주니어 개발자 하얀종이 개발자입니다.
컴퓨터에 대한 이해와 경험으로 문제를 해결하는 엔지니어가 되고 싶어요. 🙃
게시글
질문&답변
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
- 68
스터디
모집완료
이펙티브자바 3판 스터디 추가인원 모집합니다.
- 0
- 0
- 477
스터디
모집완료
이펙티브 자바 3판 스터디 모집
- 0
- 0
- 498