我想要排除一个看起来像这样的字段:
List<String> fieldNames = new ArrayList<>();
fieldNames.add("fieldA");
fieldNames.add("fieldB");
我在Dozer网页上看到我可以配置如下:
BeanMappingBuilder builder = new BeanMappingBuilder() {
protected void configure() {
mapping(AClass.class, BClass.class,
TypeMappingOptions.oneWay(),
mapNull(true)
)
.exclude("fieldA") //here i would like to add exclude but the list
}
};
但我不知道如何在.exclude方法中添加String列表....任何人都可以帮助我吗?
非常感谢!
更新
ClassA{
private String fieldA, fieldB,fieldC; //so i would like to map just the fieldC
}
ClassB{
private String fieldA, fieldB,fieldC; //so i would like to map just the fieldC
}
对于映射器配置:
List<String> fieldNames = new ArrayList<>();
fieldNames.add("fieldA");
fieldNames.add("fieldB");
我希望从mappnig中排除字段名。 所以当我映射时,我不想映射List变量... 以某种方式与......并排除......
.exclude(list.foreach(listElement -> listElement.toString())) // or i dont know how can i do that
答案 0 :(得分:1)
最后我做了这个解决方案。
DozerBeanMapper mapper = new DozerBeanMapper();
List<String> excludeList = new ArrayList<>();
excludeList.add("fieldA");
BeanMappingBuilder builder = new BeanMappingBuilder() {
protected void configure() {
TypeMappingBuilder typeMappingBuilder = mapping(ClassA.class, ClassB.class);
excludeList.forEach(typeMappingBuilder::exclude);
};
mapper.addMapping(builder);