Browse Source

fix cglib bug

Looly 5 years ago
parent
commit
4949756dd6

+ 6 - 6
hutool-extra/src/main/java/cn/hutool/extra/cglib/BeanCopierCache.java

@@ -27,10 +27,9 @@ public enum BeanCopierCache {
 	 * @param targetClass 目标Bean的类
 	 * @param converter   转换器
 	 * @return Map中对应的BeanCopier
-	 * @since 5.4.1
 	 */
 	public BeanCopier get(Class<?> srcClass, Class<?> targetClass, Converter converter) {
-		String key = genKey(srcClass, targetClass, converter);
+		final String key = genKey(srcClass, targetClass, converter);
 		return cache.get(key, () -> BeanCopier.create(srcClass, targetClass, converter != null));
 	}
 
@@ -41,11 +40,12 @@ public enum BeanCopierCache {
 	 * @param targetClass 目标Bean的类
 	 * @param converter   转换器
 	 * @return 属性名和Map映射的key
-	 * @since 5.4.1
 	 */
 	private String genKey(Class<?> srcClass, Class<?> targetClass, Converter converter) {
-
-		return converter == null ? StrUtil.format("{}#{}", srcClass.getName(), targetClass.getName())
-				: StrUtil.format("{}#{}#{}", srcClass.getName(), targetClass.getName(), converter.getClass().getName());
+		String key = StrUtil.format("{}#{}", srcClass.getName(), targetClass.getName());
+		if(null != converter){
+			key += "#" + converter.getClass().getName();
+		}
+		return key;
 	}
 }

+ 7 - 11
hutool-extra/src/main/java/cn/hutool/extra/cglib/CglibUtil.java

@@ -6,6 +6,7 @@ import net.sf.cglib.beans.BeanCopier;
 import net.sf.cglib.beans.BeanMap;
 import net.sf.cglib.core.Converter;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.function.BiConsumer;
 import java.util.function.Supplier;
@@ -27,7 +28,6 @@ public class CglibUtil {
 	 * @param source      源bean对象
 	 * @param targetClass 目标bean类,自动实例化此对象
 	 * @return 目标对象
-	 * @since 5.4.1
 	 */
 	public static <T> T copy(Object source, Class<T> targetClass) {
 		return copy(source, targetClass, null);
@@ -42,7 +42,6 @@ public class CglibUtil {
 	 * @param targetClass 目标bean类,自动实例化此对象
 	 * @param converter   转换器,无需可传{@code null}
 	 * @return 目标对象
-	 * @since 5.4.1
 	 */
 	public static <T> T copy(Object source, Class<T> targetClass, Converter converter) {
 		final T target = ReflectUtil.newInstanceIfPossible(targetClass);
@@ -55,7 +54,6 @@ public class CglibUtil {
 	 *
 	 * @param source 源bean对象
 	 * @param target 目标bean对象
-	 * @since 5.4.1
 	 */
 	public static void copy(Object source, Object target) {
 		copy(source, target, null);
@@ -82,14 +80,13 @@ public class CglibUtil {
 	/**
 	 * 拷贝List Bean对象属性
 	 *
-	 * @param source 源bean对象list
-	 * @param target 目标bean对象
 	 * @param <S>    源bean类型
 	 * @param <T>    目标bean类型
+	 * @param source 源bean对象list
+	 * @param target 目标bean对象
 	 * @return 目标bean对象list
-	 * @since 5.4.1
 	 */
-	public static <S, T> List<T> copyList(List<S> source, Supplier<T> target) {
+	public static <S, T> List<T> copyList(Collection<S> source, Supplier<T> target) {
 		return copyList(source, target, null, null);
 	}
 
@@ -104,7 +101,7 @@ public class CglibUtil {
 	 * @return 目标bean对象list
 	 * @since 5.4.1
 	 */
-	public static <S, T> List<T> copyList(List<S> source, Supplier<T> target, Converter converter) {
+	public static <S, T> List<T> copyList(Collection<S> source, Supplier<T> target, Converter converter) {
 		return copyList(source, target, converter, null);
 	}
 
@@ -119,7 +116,7 @@ public class CglibUtil {
 	 * @return 目标bean对象list
 	 * @since 5.4.1
 	 */
-	public static <S, T> List<T> copyList(List<S> source, Supplier<T> target, BiConsumer<S, T> callback) {
+	public static <S, T> List<T> copyList(Collection<S> source, Supplier<T> target, BiConsumer<S, T> callback) {
 		return copyList(source, target, null, callback);
 	}
 
@@ -133,9 +130,8 @@ public class CglibUtil {
 	 * @param <S>       源bean类型
 	 * @param <T>       目标bean类型
 	 * @return 目标bean对象list
-	 * @since 5.4.1
 	 */
-	public static <S, T> List<T> copyList(List<S> source, Supplier<T> target, Converter converter, BiConsumer<S, T> callback) {
+	public static <S, T> List<T> copyList(Collection<S> source, Supplier<T> target, Converter converter, BiConsumer<S, T> callback) {
 		return source.stream().map(s -> {
 			T t = target.get();
 			copy(source, t, converter);