【发布时间】:2019-04-11 22:37:50
【问题描述】:
我在尝试使用 Java 8 中的模型映射器时遇到了一些问题。 我有一个对象“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。
我只需要文档列表的第一个对象。
我该如何解决这个问题?
【问题讨论】:
标签: java converters modelmapper