当我尝试在Java 8中使用Model Mapper时,我遇到了一些问题。我有一个对象“Person”和一个对象“Documents”我有类似这样的情况:
public class Doc {
private Integer type;
private List<Documento> documentos = null;
private Boolean flag;
}
public class Document {
private Long doc1;
private Long doc2;
private Long doc3;
}
public class Person {
private Integer type;
private Long doc1;
private Long doc2;
private Long doc3;
private Boolean flag;
}
modelMapper.addMappings(new PropertyMap<Person, Doc>() {
@Override
protected void configure() {
map().setType(source.getType());
map().setDoc1(source.getDocument().get(0).getDoc1().longValue());
map().setDoc2(source.getDocument().get(0).getDoc2().longValue());
map().setDoc3(source.getDocument().get(0).getDoc3().longValue());
map()setFlag(source.getFlag());
}
});
但是,这不起作用。
源方法java.util.List.get()无效。确保该方法的参数为零,并且不返回void。
我只需要文档列表的第一个对象。
我该如何解决这个问题?
看看Hugues M.的这个解决方案:ModelMapper: Ensure that method has zero parameters and does not return void回答了一个类似的问题,涉及你得到的例外。