This commit is contained in:
Looly
2026-01-05 21:22:58 +08:00
parent 517bbbb899
commit 1a9696e8ac
8 changed files with 94 additions and 14 deletions

View File

@@ -20,7 +20,7 @@ package cn.hutool.v7.core.collection.queue;
* Linked接口定义了一个链式数据结构的通用接口<br>
* 链式结构中每个元素都包含两个指针,分别指向前一个元素和后一个元素。
*
* @param <T> 泛型参数表示链式结构中元素的类型必须继承自Linked<T>接口
* @param <T> 泛型参数,表示链式结构中元素的类型,必须继承自{@code Linked<T>}接口
* @author Looly
*/
public interface Linked<T extends Linked<T>> {

View File

@@ -39,7 +39,13 @@ public class KParameter {
METHOD_GET_NAME = MethodUtil.getMethod(kParameterClass, "getName");
METHOD_GET_TYPE = MethodUtil.getMethod(kParameterClass, "getType");
final Class<?> kTypeClass = ClassLoaderUtil.loadClass("kotlin.reflect.jvm.internal.KTypeImpl");
Class<?> kTypeClass;
try{
// Kotlin 2.3.0+
kTypeClass = ClassLoaderUtil.loadClass("kotlin.reflect.jvm.internal.types.AbstractKType");
} catch (final Exception e) {
kTypeClass = ClassLoaderUtil.loadClass("kotlin.reflect.jvm.internal.KTypeImpl");
}
METHOD_GET_JAVA_TYPE = MethodUtil.getMethod(kTypeClass, "getJavaType");
}

View File

@@ -38,7 +38,7 @@ public class KClassUtilTest {
final List<?> constructors = KClassUtil.getConstructors(TestKBean.class);
Assertions.assertEquals(1, constructors.size());
Assertions.assertEquals("kotlin.reflect.jvm.internal.KFunctionImpl",
Assertions.assertEquals("kotlin.reflect.jvm.internal.DescriptorKFunction",
constructors.get(0).getClass().getName());
}

View File

@@ -25,7 +25,7 @@
<parent>
<groupId>cn.hutool.v7</groupId>
<artifactId>hutool-parent</artifactId>
<version>7.0.0.M1</version>
<version>7.0.0-M5-SNAPSHOT</version>
</parent>
<artifactId>hutool-jmh</artifactId>
@@ -37,6 +37,11 @@
<!-- 此模块不部署 -->
<maven.deploy.skip>true</maven.deploy.skip>
<jmh.version>1.37</jmh.version>
<jackson.version>2.20.1</jackson.version>
<fastjson2.version>2.0.60</fastjson2.version>
<gson.version>2.13.2</gson.version>
<moshi.version>1.15.2</moshi.version>
</properties>
<dependencies>
@@ -89,7 +94,7 @@
<dependency>
<groupId>com.squareup.moshi</groupId>
<artifactId>moshi</artifactId>
<version>1.15.1</version>
<version>${moshi.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -36,8 +36,8 @@
<Automatic-Module-Name>cn.hutool.v7.json</Automatic-Module-Name>
<!-- versions -->
<jjwt.version>0.13.0</jjwt.version>
<jackson.version>2.20.0</jackson.version>
<fastjson2.version>2.0.59</fastjson2.version>
<jackson.version>2.20.1</jackson.version>
<fastjson2.version>2.0.60</fastjson2.version>
<gson.version>2.13.2</gson.version>
<moshi.version>1.15.2</moshi.version>
</properties>

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2026 Hutool Team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hutool.v7.json.kotlin;
import cn.hutool.v7.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class JsonToKotlinBeanTest {
@Test
void toBeanTest() {
final TestKBeanForJson bean = JSONUtil.parseObj("{\"id\":\"VampireAchao\", \"name\":\"阿超\", \"country\":\"中国\"}").toBean(TestKBeanForJson.class);
assertEquals("VampireAchao", bean.getId());
assertEquals("阿超", bean.getName());
assertEquals("中国", bean.getCountry());
}
@Test
void toBeanByFastJsonTest() {
final TestKBeanForJson javaObject = JSON.parseObject("{\"id\":\"VampireAchao\", \"name\":\"阿超\", \"country\":\"中国\"}").toJavaObject(TestKBeanForJson.class);
assertEquals("VampireAchao", javaObject.getId());
assertEquals("阿超", javaObject.getName());
assertEquals("中国", javaObject.getCountry());
}
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2026 Hutool Team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hutool.v7.json.kotlin
data class TestKBeanForJson(val id: String, var name: String?, var country: String?){
init {
//println("CTOR called: id=$id, name=$name, country=$country")
}
}

19
pom.xml
View File

@@ -47,19 +47,24 @@
<module>hutool-socket</module>
<module>hutool-swing</module>
<module>hutool-ai</module>
<!-- 性能测试,此模块不发布 -->
<module>hutool-jmh</module>
</modules>
<properties>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>utf-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<Automatic-Module-Name>cn.hutool.v7</Automatic-Module-Name>
<!-- 兼容旧版 Maven -->
<argLine>-Dfile.encoding=UTF-8</argLine>
<!-- versions -->
<compile.version>17</compile.version>
<junit.version>6.0.0</junit.version>
<junit.version>6.0.1</junit.version>
<lombok.version>1.18.42</lombok.version>
<kotlin-version>2.2.20</kotlin-version>
<bouncycastle.version>1.82</bouncycastle.version>
<kotlin-version>2.3.0</kotlin-version>
<bouncycastle.version>1.83</bouncycastle.version>
</properties>
<dependencies>
@@ -217,7 +222,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.19.1</version>
<version>2.20.1</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
@@ -257,7 +262,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<version>3.4.0</version>
<executions>
<execution>
<id>oss</id>