Какой самый быстрый способ перевести bean на другой bean без getset? - PullRequest
0 голосов
/ 18 сентября 2018

Я пробую несколько способов передачи данных между компонентами.Самый быстрый способ - это getset bean.Второй самый быстрый способ - org.springframework.cglib.beans.BeanCopier.Есть ли более быстрый способ, чем BeanCopier?

    LOGGER.info("getset start trans data");
    commentList.stream().map(
            comment -> {
                CommentVO commentVO = new CommentVO();
                commentVO.setId(comment.getId());
                commentVO.setContent(comment.getContent());
                return commentVO;
            }
    ).collect(Collectors.toList());
    LOGGER.info("getset trans data compelete");

    LOGGER.info("Spring.BeanUtils start trans data");
    commentList.stream().map(
            comment -> {
                CommentVO commentVO = new CommentVO();
                BeanUtils.copyProperties(comment, commentVO);
                return commentVO;
            }
    ).collect(Collectors.toList());
    LOGGER.info("Spring.BeanUtils trans data compelete");

    LOGGER.info("BeanCopier start trans data");
    commentList.stream().map(
            comment -> {
                CommentVO commentVO = new CommentVO();
                BeanCopier beanCopier = BeanCopier.create(Comment.class, CommentVO.class, false);
                beanCopier.copy(comment, commentVO, null);

                return commentVO;
            }
    ).collect(Collectors.toList());
    LOGGER.info("BeanCopier trans data compelete");

    LOGGER.info("FASTJSON start trans data");
    commentList.stream().map(
            comment -> JSON.parseObject(JSON.toJSONString(comment), CommentVO.class)
    ).collect(Collectors.toList());
    LOGGER.info("FASTJSON trans data compelete");

результат:

14:21:09.343 [main] INFO com.southcn.nfplus.cmt.web.Main - getset start trans data
14:21:09.360 [main] INFO com.southcn.nfplus.cmt.web.Main - getset trans data compelete
14:21:09.360 [main] INFO com.southcn.nfplus.cmt.web.Main - Spring.BeanUtils start trans data
14:21:09.657 [main] INFO com.southcn.nfplus.cmt.web.Main - Spring.BeanUtils trans data compelete
14:21:09.657 [main] INFO com.southcn.nfplus.cmt.web.Main - BeanCopier start trans data
14:21:09.805 [main] INFO com.southcn.nfplus.cmt.web.Main - BeanCopier trans data compelete
14:21:09.805 [main] INFO com.southcn.nfplus.cmt.web.Main - FASTJSON start trans data
14:21:10.396 [main] INFO com.southcn.nfplus.cmt.web.Main - FASTJSON trans data compelete    
...