mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
@@ -6,6 +6,8 @@ import cn.hutool.core.lang.Editor;
|
||||
import cn.hutool.core.lang.func.Func1;
|
||||
import cn.hutool.core.lang.func.LambdaUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -70,8 +72,19 @@ public class CopyOptions implements Serializable {
|
||||
/**
|
||||
* 自定义类型转换器,默认使用全局万能转换器转换
|
||||
*/
|
||||
protected TypeConverter converter = (type, value) ->
|
||||
Convert.convertWithCheck(type, value, null, ignoreError);
|
||||
protected TypeConverter converter = (type, value) -> {
|
||||
if(null == value){
|
||||
return null;
|
||||
}
|
||||
|
||||
final String name = value.getClass().getName();
|
||||
if(ArrayUtil.contains(new String[]{"cn.hutool.json.JSONObject", "cn.hutool.json.JSONArray"}, name)){
|
||||
// 由于设计缺陷导致JSON转Bean时无法使用自定义的反序列化器,此处采用反射方式修复bug,此类问题会在6.x解决
|
||||
return ReflectUtil.invoke(value, "toBean", ObjectUtil.defaultIfNull(type, Object.class));
|
||||
}
|
||||
|
||||
return Convert.convertWithCheck(type, value, null, ignoreError);
|
||||
};
|
||||
|
||||
//region create
|
||||
|
||||
|
@@ -55,7 +55,7 @@ public abstract class AbstractConverter<T> implements Converter<T>, Serializable
|
||||
// 除Map外,已经是目标类型,不需要转换(Map类型涉及参数类型,需要单独转换)
|
||||
return targetType.cast(value);
|
||||
}
|
||||
T result = convertInternal(value);
|
||||
final T result = convertInternal(value);
|
||||
return ((null == result) ? defaultValue : result);
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
|
Reference in New Issue
Block a user