코드

import java.util.List;
import java.util.stream.Collectors;

public class UserDtoMapper {

    public static GetUserDto mapUserWithBoards(UserWithBoards userWithBoards, int depth) {
        GetUserDto.GetUserDtoBuilder userDtoBuilder = GetUserDto.builder()
                .id(userWithBoards.getId())
                .userId(userWithBoards.getUserId())
                .userPassword(userWithBoards.getUserPassword())
                .name(userWithBoards.getName())
                .gender(userWithBoards.getGender())
                .phone(userWithBoards.getPhone())
                .createdAt(userWithBoards.getCreatedAt())
                .updatedAt(userWithBoards.getUpdatedAt());

        if (depth > 0) {
            List<GetBoardDto> boardDtos = userWithBoards.getBoards()
                    .stream()
                    .map(board -> mapBoard(board, depth - 1))
                    .collect(Collectors.toList());

            userDtoBuilder.getBoards(boardDtos);
        }

        return userDtoBuilder.build();
    }

    private static GetBoardDto mapBoard(Board board, int depth) {
        GetBoardDto.GetBoardDtoBuilder boardDtoBuilder = GetBoardDto.builder()
                .id(board.getId())
                .title(board.getTitle())
                .content(board.getContent())
                .createdAt(board.getCreatedAt())
                .updatedAt(board.getUpdatedAt());

        if (depth > 0) {
            List<GetBoardDto> childBoardDtos = board.getChildren()
                    .stream()
                    .map(childBoard -> mapBoard(childBoard, depth - 1))
                    .collect(Collectors.toList());

            boardDtoBuilder.getBoards(childBoardDtos);
        }

        return boardDtoBuilder.build();
    }
}

솔트 + 그룹핑

private Map<String, Map<String, List<CertDetailDto>>> toEtcAccDetailDtoList(
        Stream<CertList> certList) {
        Map<String, List<CertDetailDto>> listMap = certList.map(cert -> CertDetailDto.builder()
                .certType(getCertTypeString(cert))
                .certNum(cert.getCertlistNumber())
                .certManufacturer(cert.getCertListManufacturer())
                .certImporter(cert.getCertListImporter())
                .certModelName(cert.getCertListModel())
                .certResult(cert.getCertlistResult())
                .certGroup(cert.getCertlistGroup())
                .certValue(cert.getCertlistValue())
                .certReason(cert.getCertlistReason())
                .productName(cert.getCertListProductname())
                .build())
            .collect(Collectors.groupingBy(CertDetailDto::getCertGroup));