How to map collections in Dozer

前端 未结 8 758
悲&欢浪女
悲&欢浪女 2020-12-14 17:25

I\'d like to do something like:

ArrayList objects = new ArrayList();
...
DozerBeanMapper MAPPER = new DozerBeanMapper         


        
8条回答
  •  感动是毒
    2020-12-14 17:46

    Not really an improvement, more like a syntactic sugar that can be achieved thanks to Guava (and most likely similar thing is possible with Apache Commons):

    final List mapped = Lists.newArrayList(Iterables.transform(inputList, new Function() {
        @Override public MyPojo apply(final MyEntity arg) {
            return mapper.map(arg, MyPojo.class);
        }
    }));
    

    This can also be turned into a generic function - as suggested in other answers.

提交回复
热议问题