mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复BeanUtil.copyProperties 包含EnumSet ,类型转换异常问题
This commit is contained in:
parent
47198cc819
commit
8ff1368f30
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.8.10.M1 (2022-11-11)
|
# 5.8.10.M1 (2022-11-12)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【http 】 HttpResponse增加getFileNameFromDisposition方法(pr#2676@Github)
|
* 【http 】 HttpResponse增加getFileNameFromDisposition方法(pr#2676@Github)
|
||||||
@ -25,6 +25,7 @@
|
|||||||
* 【core 】 修复 BeanUtil#copyProperties 源对象与目标对象都是 Map 时设置忽略属性无效问题(pr#2698@Github)
|
* 【core 】 修复 BeanUtil#copyProperties 源对象与目标对象都是 Map 时设置忽略属性无效问题(pr#2698@Github)
|
||||||
* 【core 】 修复ChineseDate传入农历日期非闰月时获取公历错误问题(issue#I5YB1A@Gitee)
|
* 【core 】 修复ChineseDate传入农历日期非闰月时获取公历错误问题(issue#I5YB1A@Gitee)
|
||||||
* 【core 】 修复key为弱引用 value为强引用 会导致key无法被回收 弱引用失效问题(pr#2723@Github)
|
* 【core 】 修复key为弱引用 value为强引用 会导致key无法被回收 弱引用失效问题(pr#2723@Github)
|
||||||
|
* 【core 】 修复BeanUtil.copyProperties 包含EnumSet ,类型转换异常问题(pr#2684@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.9 (2022-10-22)
|
# 5.8.9 (2022-10-22)
|
||||||
|
@ -7,6 +7,7 @@ import cn.hutool.core.comparator.PropertyComparator;
|
|||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.convert.ConverterRegistry;
|
import cn.hutool.core.convert.ConverterRegistry;
|
||||||
import cn.hutool.core.exceptions.UtilException;
|
import cn.hutool.core.exceptions.UtilException;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.lang.Editor;
|
import cn.hutool.core.lang.Editor;
|
||||||
import cn.hutool.core.lang.Filter;
|
import cn.hutool.core.lang.Filter;
|
||||||
import cn.hutool.core.lang.Matcher;
|
import cn.hutool.core.lang.Matcher;
|
||||||
@ -964,7 +965,7 @@ public class CollUtil {
|
|||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
*/
|
*/
|
||||||
public static <T> BlockingQueue<T> newBlockingQueue(int capacity, boolean isLinked) {
|
public static <T> BlockingQueue<T> newBlockingQueue(int capacity, boolean isLinked) {
|
||||||
BlockingQueue<T> queue;
|
final BlockingQueue<T> queue;
|
||||||
if (isLinked) {
|
if (isLinked) {
|
||||||
queue = new LinkedBlockingDeque<>(capacity);
|
queue = new LinkedBlockingDeque<>(capacity);
|
||||||
} else {
|
} else {
|
||||||
@ -973,6 +974,18 @@ public class CollUtil {
|
|||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建新的集合对象
|
||||||
|
*
|
||||||
|
* @param <T> 集合类型
|
||||||
|
* @param collectionType 集合类型
|
||||||
|
* @return 集合类型对应的实例
|
||||||
|
* @since 3.0.8
|
||||||
|
*/
|
||||||
|
public static <T> Collection<T> create(Class<?> collectionType) {
|
||||||
|
return create(collectionType, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建新的集合对象,返回具体的泛型集合
|
* 创建新的集合对象,返回具体的泛型集合
|
||||||
*
|
*
|
||||||
@ -982,8 +995,8 @@ public class CollUtil {
|
|||||||
* @since v5
|
* @since v5
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
private static <T> Collection<T> doCreate(Class<?> collectionType, Class<T> elementType) {
|
public static <T> Collection<T> create(Class<?> collectionType, Class<T> elementType) {
|
||||||
Collection<T> list;
|
final Collection<T> list;
|
||||||
if (collectionType.isAssignableFrom(AbstractCollection.class)) {
|
if (collectionType.isAssignableFrom(AbstractCollection.class)) {
|
||||||
// 抽象集合默认使用ArrayList
|
// 抽象集合默认使用ArrayList
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
@ -1003,7 +1016,7 @@ public class CollUtil {
|
|||||||
return CompareUtil.compare(o1.toString(), o2.toString());
|
return CompareUtil.compare(o1.toString(), o2.toString());
|
||||||
});
|
});
|
||||||
} else if (collectionType.isAssignableFrom(EnumSet.class)) {
|
} else if (collectionType.isAssignableFrom(EnumSet.class)) {
|
||||||
list = (Collection<T>) EnumSet.noneOf((Class<Enum>) elementType);
|
list = (Collection<T>) EnumSet.noneOf(Assert.notNull((Class<Enum>) elementType));
|
||||||
}
|
}
|
||||||
|
|
||||||
// List
|
// List
|
||||||
@ -1017,7 +1030,7 @@ public class CollUtil {
|
|||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
list = (Collection<T>) ReflectUtil.newInstance(collectionType);
|
list = (Collection<T>) ReflectUtil.newInstance(collectionType);
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
// 无法创建当前类型的对象,尝试创建父类型对象
|
// 无法创建当前类型的对象,尝试创建父类型对象
|
||||||
final Class<?> superclass = collectionType.getSuperclass();
|
final Class<?> superclass = collectionType.getSuperclass();
|
||||||
if (null != superclass && collectionType != superclass) {
|
if (null != superclass && collectionType != superclass) {
|
||||||
@ -1029,32 +1042,6 @@ public class CollUtil {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建新的集合对象,返回具体的泛型集合
|
|
||||||
*
|
|
||||||
* @param <T> 集合元素类型
|
|
||||||
* @param collectionType 集合类型,rawtype 如 ArrayList.class, EnumSet.class ...
|
|
||||||
* @return 集合类型对应的实例
|
|
||||||
* @since v5
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public static <T> Collection<T> create(Class<?> collectionType, Class<T> elementType) {
|
|
||||||
return doCreate(collectionType, elementType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建新的集合对象
|
|
||||||
*
|
|
||||||
* @param <T> 集合类型
|
|
||||||
* @param collectionType 集合类型
|
|
||||||
* @return 集合类型对应的实例
|
|
||||||
* @since 3.0.8
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
public static <T> Collection<T> create(Class<?> collectionType) {
|
|
||||||
return doCreate(collectionType, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 去重集合
|
* 去重集合
|
||||||
*
|
*
|
||||||
|
@ -233,7 +233,7 @@ public class ExceptionUtil {
|
|||||||
* 堆栈转为完整字符串
|
* 堆栈转为完整字符串
|
||||||
*
|
*
|
||||||
* @param throwable 异常对象
|
* @param throwable 异常对象
|
||||||
* @param limit 限制最大长度,>0表示不限制长度
|
* @param limit 限制最大长度,<0表示不限制长度
|
||||||
* @param replaceCharToStrMap 替换字符为指定字符串
|
* @param replaceCharToStrMap 替换字符为指定字符串
|
||||||
* @return 堆栈转为的字符串
|
* @return 堆栈转为的字符串
|
||||||
*/
|
*/
|
||||||
|
@ -653,16 +653,18 @@ public class BeanUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void beanWithEnumSetTest() {
|
public void beanWithEnumSetTest() {
|
||||||
Vto v1 = new Vto();
|
final Vto v1 = new Vto();
|
||||||
v1.setVersions(EnumSet.allOf(Version.class));
|
v1.setVersions(EnumSet.allOf(Version.class));
|
||||||
System.out.println(BeanUtil.copyProperties(v1, Vto.class));
|
final Vto v2 = BeanUtil.copyProperties(v1, Vto.class);
|
||||||
|
Assert.assertNotNull(v2);
|
||||||
|
Assert.assertNotNull(v2.getVersions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void enumSetTest() {
|
public void enumSetTest() {
|
||||||
final Collection<Version> objects = CollUtil.create(EnumSet.class, Version.class);
|
final Collection<Version> objects = CollUtil.create(EnumSet.class, Version.class);
|
||||||
System.out.println(objects.getClass());
|
Assert.assertNotNull(objects);
|
||||||
System.out.println(objects);
|
Assert.assertTrue(EnumSet.class.isAssignableFrom(objects.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Station extends Tree<Long> {}
|
static class Station extends Tree<Long> {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user