如何使用 Dozer 排除 java 中的字符串列表?
How to exclude List of Strings in java with Dozer?
我想排除如下所示的字段:
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 方法中....任何人都可以帮助我吗?
非常感谢!
更新
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");
会有一些我想从映射中排除的字段名。
所以当我映射时,我不想映射 List 变量......
以某种方式去 for...并排除它...
.exclude(list.foreach(listElement -> listElement.toString())) // or i dont know how can i do that
我终于做了这个解决方案。
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);
我想排除如下所示的字段:
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 方法中....任何人都可以帮助我吗?
非常感谢!
更新
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");
会有一些我想从映射中排除的字段名。 所以当我映射时,我不想映射 List 变量...... 以某种方式去 for...并排除它...
.exclude(list.foreach(listElement -> listElement.toString())) // or i dont know how can i do that
我终于做了这个解决方案。
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);