Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buildFromJson function into data class to build data class object from JSONObject #348

Closed
varenyzc opened this issue May 18, 2021 · 3 comments
Assignees
Milestone

Comments

@varenyzc
Copy link

rt,目前需要写个插件,可生成class中包含一个static方法,用于从jsonObject转化为class实体类,不知插件是否支持?

e.g:
json: { "a":1,"b":true,"c":""}
转化为data class:
data class Test (
val a: Int,
val b: Boolean,
val c: String
) {
companion object {

    @JvmStatic
    fun buildFromJson(jsonObject: JSONObject?): Test? {
        jsonObject?.run {
            return Test(
                    optInt("a"),
                    optBoolean("b"),
                    optString("c")
            )
        }
        return null
    }
}

}

@wuseal
Copy link
Owner

wuseal commented May 18, 2021

@varenyzc
Copy link
Author

@wuseal 感谢回复。已在实现中~

@wuseal wuseal changed the title 插件支持填充class的内容吗 Add buildFromJson function into data class to build data class object from JSONObject May 26, 2021
@wuseal wuseal added this to the 3.7.1 milestone May 26, 2021
@wuseal
Copy link
Owner

wuseal commented May 26, 2021

Implemented by @varenyzc #349

@wuseal wuseal closed this as completed May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants