mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix TypeReference not fit Type
This commit is contained in:
@@ -51,6 +51,7 @@ import cn.hutool.core.convert.impl.URIConverter;
|
||||
import cn.hutool.core.convert.impl.URLConverter;
|
||||
import cn.hutool.core.convert.impl.UUIDConverter;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
@@ -199,6 +200,10 @@ public class ConverterRegistry implements Serializable{
|
||||
type = defaultValue.getClass();
|
||||
}
|
||||
|
||||
if(type instanceof TypeReference) {
|
||||
type = ((TypeReference<?>)type).getType();
|
||||
}
|
||||
|
||||
// 标准转换器
|
||||
final Converter<T> converter = getConverter(type, isCustomFirst);
|
||||
if (null != converter) {
|
||||
|
@@ -7,6 +7,7 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
|
||||
/**
|
||||
* 类型转换工具单元测试
|
||||
@@ -26,13 +27,15 @@ public class ConvertTest {
|
||||
public void toStrTest() {
|
||||
int a = 1;
|
||||
long[] b = { 1, 2, 3, 4, 5 };
|
||||
|
||||
Console.log(Convert.convert(String.class, b));
|
||||
|
||||
String aStr = Convert.toStr(a);
|
||||
Assert.assertEquals("1", aStr);
|
||||
String bStr = Convert.toStr(b);
|
||||
Assert.assertEquals("[1, 2, 3, 4, 5]", Convert.toStr(bStr));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void toStrTest2() {
|
||||
String result = Convert.convert(String.class, "aaaa");
|
||||
|
Reference in New Issue
Block a user