这个问题与AutoMapper无关。我的问题是关于java中的ModelMapper,但是我不能为模型映射器创建新的标签,因为我的名声很小。很抱歉给你造成了混乱。
无论如何,我的问题是,modelmapper库是否支持像arraylist或hashset这样的集合?它似乎不支持集合到集合映射。是真的吗?
发布于 2013-07-29 16:41:04
您还可以直接映射集合():
List<Person> persons = getPersons();
// Define the target type
java.lang.reflect.Type targetListType = new TypeToken<List<PersonDTO>>() {}.getType();
List<PersonDTO> personDTOs = mapper.map(persons, targetListType);
发布于 2019-03-22 23:22:13
或者使用Java 8:
List<Target> targetList =
sourceList
.stream()
.map(source -> modelMapper.map(source, Target.class))
.collect(Collectors.toList());
发布于 2017-01-19 21:48:43
如果您使用数组,也可以避免使用TypeToken:
List<PropertyDefinition<?>> list = ngbaFactory.convertStandardDefinitions(props);
ModelMapper modelMapper = new ModelMapper();
PropertyDefinitionDto[] asArray = modelMapper.map(list, PropertyDefinitionDto[].class);
https://stackoverflow.com/questions/7199916
复制相似问题