修复JsonUtil.toBean泛型数组类型丢失问题(pr#3876@Github)

This commit is contained in:
Looly
2025-03-03 12:05:32 +08:00
parent bb0eb91087
commit 9b19bf84a8
3 changed files with 12 additions and 2 deletions

View File

@@ -418,7 +418,7 @@ public class TypeUtil {
* 2. 泛型变量类似于T
* </pre>
*
* @param type 类
* @param type 泛型
* @param typeVariable 泛型变量例如T等
* @return 实际类型可能为Class等
*/
@@ -431,7 +431,10 @@ public class TypeUtil {
}
// pr#3876 解决泛型数组泛型类型无法识别问题
if (typeVariable instanceof GenericArrayType) {
return ActualTypeMapperPool.getActualType(type, (GenericArrayType) typeVariable);
final Type actualType = ActualTypeMapperPool.getActualType(type, (GenericArrayType) typeVariable);
if(null != actualType){
return actualType;
}
}
// 没有需要替换的泛型变量,原样输出

View File

@@ -30,6 +30,11 @@ import java.util.Objects;
*/
class ClassUtilTest {
@Test
void forNameTest() {
Assertions.assertEquals(String.class, ClassUtil.forName("java.lang.String", false, null));
}
@Test
void testGetSuperClasses() {
// if root is null