Commit d57e4f9b authored by liaozan's avatar liaozan 🏀

Make BeanCopyUtils#convert quietly

parent e1b2f2c7
package com.schbrain.common.util; package com.schbrain.common.util;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.convert.ConverterRegistry;
import cn.hutool.core.lang.Singleton; import cn.hutool.core.lang.Singleton;
import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.ReflectUtil;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
...@@ -10,6 +11,7 @@ import org.springframework.cglib.beans.BeanCopier; ...@@ -10,6 +11,7 @@ import org.springframework.cglib.beans.BeanCopier;
import org.springframework.cglib.core.Converter; import org.springframework.cglib.core.Converter;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -67,6 +69,11 @@ public class BeanCopyUtils { ...@@ -67,6 +69,11 @@ public class BeanCopyUtils {
return CACHE_KEY_JOINER.join(source.getName(), target.getName()); return CACHE_KEY_JOINER.join(source.getName(), target.getName());
} }
/**
* 基于 hutool 实现的转换
*
* @see ConverterRegistry#getConverter(Type, boolean)
*/
private static class DefaultConverter implements Converter { private static class DefaultConverter implements Converter {
private static final DefaultConverter INSTANCE = new DefaultConverter(); private static final DefaultConverter INSTANCE = new DefaultConverter();
...@@ -79,13 +86,9 @@ public class BeanCopyUtils { ...@@ -79,13 +86,9 @@ public class BeanCopyUtils {
if (ClassUtils.isAssignableValue(targetType, value)) { if (ClassUtils.isAssignableValue(targetType, value)) {
return value; return value;
} }
Object converted = Convert.convertQuietly(targetType, value, null); return Convert.convertQuietly(targetType, value);
if (converted == null) {
log.warn("Could not copy {} to {}, value type: {}", value, targetType, value.getClass());
}
return converted;
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment