Json.kt
6.2.1indexedEnables intuitive JSON-to-class conversion using delegated properties, supporting seamless integration for Java 8+, Android, and JavaScript environments, with documentation readily accessible online.
Enables intuitive JSON-to-class conversion using delegated properties, supporting seamless integration for Java 8+, Android, and JavaScript environments, with documentation readily accessible online.
Surfaced from shared tags and platforms — no rankings paid for.
委譲プロパティを使い, 直感的に JSON を Kotlin のクラスに変換できます。
Using delegated properties, you can intuitively convert JSON to Kotlin classes.
現時点では JVM (Android), JS target に対応しています。
At present, it supports Java 8 or later, Android, and JavaScript target.
ドキュメントは こちら で公開しています。
Documentation is available at here.
Json.kt はバージョン 6.0.2 から Maven Central で公開されています。以前の Bintray リポジトリはもう利用できません。
Json.kt is now available in the Maven Central since version 6.0.2. The previous Bintray repository is no longer available.
dependencies {
implementation("blue.starry:jsonkt:$JsonKtVersion")
}
Json.kt is provided under the MIT License.
Copyright (c) 2017-2021 StarryBlueSky.
data class Model(override val json: JsonObject): JsonModel {
val a by int
val b by float
val c by string
val d by intList
val e by model { E(it) }
val f by modelList { E(it) }
data class E(override val json: JsonObject): JsonModel {
val x by nullableString
val y by double
val z by int
}
}
private val json = """{
"a": 1,
"b": 2.3,
"c": "hoge",
"d": [2, 3, 5, 7],
"e": {
"x": "1",
"y": 2.0,
"z": 3
},
"f": [
{
"x": "1",
"y": 2.0001,
"z": 3
},
{
"x": null,
"y": 20.00001,
"z": 30
}
]
}"""
fun main() {
val model = json.parseObject { Model(it) }
assertEquals(1, model.a)
}