我在我的休息应用程序中使用 ModelMapper。
我必须将列表转换为列表。
这是我的代码:
Converter<List<UserRole>,List<String>> listConverter = new Converter<List<UserRole>, List<String>>() {
public List<String> convert(MappingContext<List<UserRole>, List<String>> context) {
List<String> target = new ArrayList<String>();
List<UserRole> userRoles = context.getSource();
for (UserRole userRole : userRoles) {
target.add(userRole.getRole().getName());
}
return target;
}
};
PropertyMap<User, UserDTO> propertiesForConvertToDto = new PropertyMap<User, UserDTO>() {
protected void configure() {
using(listConverter).map(source.getUserRoles()).setRoles(null);
}
};
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我收到此错误:
HTTP Status 500 - Request processing failed; nested exception is org.modelmapper.MappingException: ModelMapper mapping errors:
type Exception report
message Request processing failed; nested exception is org.modelmapper.MappingException: ModelMapper …Run Code Online (Sandbox Code Playgroud)