mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复JSON反序列化时,引用字段类型的自定义JsonDeserializer无效
This commit is contained in:
@@ -36,6 +36,7 @@ import cn.hutool.core.convert.impl.UUIDConverter;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.lang.Opt;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.util.ClassLoaderUtil;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
@@ -279,7 +280,13 @@ public class ConverterRegistry implements Serializable {
|
||||
|
||||
// 尝试转Bean
|
||||
if (BeanUtil.isBean(rowType)) {
|
||||
return new BeanConverter<T>(type).convert(value, defaultValue);
|
||||
try {
|
||||
// 由于5.x设计缺陷,JSON转bean无法实现自定义转换,因此此处临时使用反射方式获取自定义的转换器,此问题会在6.x中彻底解决。
|
||||
final Class<?> clazz = ClassLoaderUtil.loadClass("cn.hutool.json.BeanConverterForJSON");
|
||||
return ((Converter<T>)ReflectUtil.newInstance(clazz, type)).convert(value, defaultValue);
|
||||
}catch (final Throwable ignore){
|
||||
return new BeanConverter<T>(type).convert(value, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
// 无法转换
|
||||
|
@@ -31,7 +31,7 @@ public class BeanConverter<T> extends AbstractConverter<T> {
|
||||
|
||||
private final Type beanType;
|
||||
private final Class<T> beanClass;
|
||||
private final CopyOptions copyOptions;
|
||||
protected CopyOptions copyOptions;
|
||||
|
||||
/**
|
||||
* 构造,默认转换选项,注入失败的字段忽略
|
||||
|
Reference in New Issue
Block a user