mirror of https://github.com/alibaba/fastjson2.git
fix kotlin support, for issue #3288
This commit is contained in:
parent
5b34823b40
commit
3cb9068b4f
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue