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

在Kotlin对JSONObject对象使用“toJavaObject”方法转为Pojo类时,当字段首字母为大写时报错 #1611

Closed
jelipo opened this issue Nov 26, 2017 · 1 comment
Labels
Milestone

Comments

@jelipo
Copy link

jelipo commented Nov 26, 2017

Pojo

data class Test(
        @JSONField(name = "Name")
        var name: String = ""
)

当运行以下代码时报错

fun main(args: Array<String>) {
    val pristineJson = "{\"data\":{\"lists\":[{\"Name\":\"Mark\"}]}}"
    val list = JSONObject.parseObject(pristineJson).getJSONObject("data").getJSONArray("lists")
    for (i in list.indices) {
        var sss = list.getJSONObject(i)
        val single: Test = sss.toJavaObject(Test::class.java)
    }
}

当转换为字符串时就不会报错

fun main(args: Array<String>) {
    val pristineJson = "{\"data\":{\"lists\":[{\"Name\":\"Mark\"}]}}"
    val list = JSONObject.parseObject(pristineJson).getJSONObject("data").getJSONArray("lists")
    for (i in list.indices) {
        var sss = list.getJSONObject(i)
        val single: Test = JSON.parseObject(sss.toJSONString(),Test::class.java)
    }
}
@jelipo jelipo changed the title Kotlin把JSONObject转为Pojo类时,当字段首字母为大写时报错 Kotlin把JSONObject “.toJavaObject”转为Pojo类时,当字段首字母为大写时报错 Nov 26, 2017
@jelipo jelipo changed the title Kotlin把JSONObject “.toJavaObject”转为Pojo类时,当字段首字母为大写时报错 在Kotlin对JSONObject对象使用“toJavaObject”方法转为Pojo类时,当字段首字母为大写时报错 Nov 26, 2017
@wenshao wenshao added this to the 1.2.42 milestone Dec 12, 2017
@wenshao wenshao added the bug label Dec 12, 2017
@wenshao
Copy link
Member

wenshao commented Dec 14, 2017

https://github.com/alibaba/fastjson/releases/tag/1.2.42
新版已发布,请使用新版本。

@wenshao wenshao closed this as completed Dec 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants