Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 94583b7

Browse files
authored
Merge pull request #3268 from lichengwu/master
fix kotlin isXx property name
2 parents d0ddf9c + 62237d0 commit 94583b7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/main/java/com/alibaba/fastjson/util/JavaBeanInfo.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,7 @@ public static JavaBeanInfo build(Class<?> clazz //
771771
// 因此如果是kotlin的话还需要进行不一样的判断, 判断的方式是通过get方法进行判断, isAbc的get方法名为isAbc(), abc的get方法名为getAbc()
772772
if (kotlin) {
773773
String getMethodName = "g" + methodName.substring(1);
774-
if (getMethodNameList.contains(getMethodName)) {
775-
propertyName = TypeUtils.getPropertyNameByMethodName(getMethodName);
776-
} else {
777-
propertyName = "is" + getMethodName.substring(3);
778-
}
774+
propertyName = TypeUtils.getPropertyNameByMethodName(getMethodName);
779775
} else {
780776
if (TypeUtils.compatibleWithJavaBean) {
781777
propertyName = TypeUtils.decapitalize(methodName.substring(3));

src/test/java/com/alibaba/fastjson/deserializer/issue3248/TestIssue3248.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ class TestIssue3248 {
1515
@JSONField(name = "namex")
1616
var name = ""
1717

18+
var isTest: Boolean = false
19+
1820
@Test
1921
fun test() {
2022

2123
val test = TestIssue3248().also {
2224
it.name = "my name"
25+
it.isTest = true
2326
}
2427
val raw = JSON.toJSONString(test)
2528
val parsed = JSON.parseObject(raw, TestIssue3248::class.java)
2629
Assert.assertEquals(test.name, parsed.name)
30+
Assert.assertEquals(test.isTest, parsed.isTest)
2731

2832
}
2933
}

0 commit comments

Comments
 (0)