I want to exclude a fields which looks like:
List<String> fieldNames = new ArrayList<>();
fieldNames.add("fieldA");
fieldNames.add("fieldB");
And i see on Dozer webpage that I can configure somehow like:
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
}
};
But i don't know how to add a list of String to the .exclude method....can anyone helps to me?
Thanks a lot!
UPDATE
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
}
For mapper configuration:
List<String> fieldNames = new ArrayList<>();
fieldNames.add("fieldA");
fieldNames.add("fieldB");
there will be fieldnames what i would like to exclude from the mappnig. So when i mapping, i dont want to map the List variable... somehow go with for...and exclude it...
.exclude(list.foreach(listElement -> listElement.toString())) // or i dont know how can i do that
Finally i made this sollution.
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);