add propertiesFilter

This commit is contained in:
Looly
2021-03-19 16:46:36 +08:00
parent 3990516a31
commit 6d5ca7051b
3 changed files with 6 additions and 5 deletions

View File

@@ -188,7 +188,7 @@ public class BeanCopier<T> implements Copier<T>, Serializable {
throw new BeanException(e, "Get value of [{}] error!", prop.getFieldName());
}
}
if(!copyOptions.propertiesFilter.test(prop.getField(), value)) {
if(null != copyOptions.propertiesFilter && false == copyOptions.propertiesFilter.test(prop.getField(), value)) {
return;
}
if ((null == value && copyOptions.ignoreNullValue) || bean == value) {
@@ -248,9 +248,10 @@ public class BeanCopier<T> implements Copier<T>, Serializable {
// 获取属性值
Object value = valueProvider.value(providerKey, fieldType);
if(!copyOptions.propertiesFilter.test(prop.getField(), value)) {
if(null != copyOptions.propertiesFilter && false == copyOptions.propertiesFilter.test(prop.getField(), value)) {
return;
}
if ((null == value && copyOptions.ignoreNullValue) || bean == value) {
// 当允许跳过空时,跳过
// 值不能为bean本身防止循环引用

View File

@@ -87,7 +87,6 @@ public class CopyOptions implements Serializable {
* 构造拷贝选项
*/
public CopyOptions() {
this.propertiesFilter = (f, v) -> true;
}
/**
@@ -98,7 +97,7 @@ public class CopyOptions implements Serializable {
* @param ignoreProperties 忽略的目标对象中属性列表,设置一个属性列表,不拷贝这些属性值
*/
public CopyOptions(Class<?> editable, boolean ignoreNullValue, String... ignoreProperties) {
this();
this.propertiesFilter = (f, v) -> true;
this.editable = editable;
this.ignoreNullValue = ignoreNullValue;
this.ignoreProperties = ignoreProperties;