fix kotlin support, for issue #3288

This commit is contained in:
wenshao 2025-02-09 15:28:36 +08:00
parent 5b34823b40
commit 3cb9068b4f
2 changed files with 31 additions and 0 deletions

View File

@ -1297,6 +1297,10 @@ public abstract class BeanUtils {
}
String fieldName = getterName(methodName, namingStrategy);
int subIndex;
if (kotlin && (subIndex = fieldName.indexOf('-')) != -1) {
fieldName = fieldName.substring(0, subIndex);
}
if (fieldName.length() > 2
&& fieldName.charAt(0) >= 'A' && fieldName.charAt(0) <= 'Z'

View File

@ -0,0 +1,27 @@
package com.alibaba.fastjson2.issues
import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.toJSONString
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class Issue3288 {
@JvmInline
value class TestBean(val a: Int)
data class Test2(
val b: TestBean
)
@Test
fun test() {
val s1 = "{\"a\":1}"
assertEquals(s1, TestBean(1).toJSONString())
assertEquals(s1, JSON.parseObject(s1, TestBean::class.java).toJSONString())
assertEquals(s1, TestBean(1).toJSONString())
val s2 = "{\"b\":2}"
assertEquals(s2, JSON.parseObject(s2, Test2::class.java)
.toJSONString())
assertEquals(s2, JSON.parseObject(s2, Test2::class.java).toJSONString())
}
}