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

@ -3,10 +3,11 @@
-------------------------------------------------------------------------------------------------------------
# 5.6.2 (2021-03-18)
# 5.6.2 (2021-03-19)
### 新特性
* 【core 】 Validator增加车架号(车辆识别码)验证、驾驶证驾驶证档案编号的正则校验pr#280@Gitee
* 【core 】 CopyOptions增加propertiesFilterpr#281@Gitee
### Bug修复
-------------------------------------------------------------------------------------------------------------

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;