SrSouza
11/08/2020, 8:05 PMmbonnin
11/08/2020, 11:21 PMmbonnin
11/08/2020, 11:22 PMkotlinx-serialization
work using only the runtime. I guess there's a Json parser therembonnin
11/08/2020, 11:36 PM@file:DependsOn("org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.0.1")
import kotlinx.serialization.json.*
val jsonObject = JsonObject(
mapOf(
"int" to JsonPrimitive(0),
"double" to JsonPrimitive(0.5),
"string" to JsonPrimitive("String"),
"bool" to JsonPrimitive(true),
"list" to JsonArray(
listOf(
JsonPrimitive(0),
JsonPrimitive(1),
JsonPrimitive(2),
JsonPrimitive(3)
)
),
"object" to JsonObject(
mapOf("key" to JsonPrimitive("value")
)
)
)
)
println(Json.parseToJsonElement(jsonObject.toString()))
ilya.chernikov
11/10/2020, 6:03 PMmain-kts
, in particular with kotlinx.serialization
, see, e.g., the test here - https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsIT.kt#L94mbonnin
11/10/2020, 7:33 PM*.main.kts
file itself ? Or does it always need the -Xplugin
parameter?mbonnin
11/10/2020, 7:35 PM-Xplugin
is mandatory?)ilya.chernikov
11/10/2020, 7:42 PM-Xplugin
parameter to the kotlinc
. (or you can write a custom host/runner that includes the plugin by default.)
The plugin is installed along with kotlin CLI compiler, to the $KOTLIN_HOME/lib/
.mbonnin
11/12/2020, 1:16 PM-Xplugin
? 🤔
martin@MacBook:~/dev/kotlinc$ kotlinc -script serialization.main.kts
{"firstName":"James","lastName":"Bond"}
User(firstName=James, lastName=Bond)
mbonnin
11/12/2020, 1:17 PMmbonnin
11/12/2020, 1:18 PMilya.chernikov
11/12/2020, 3:18 PMmbonnin
11/13/2020, 3:00 PM#!$KOTLIN_HOME/bin/kotlinc -Xplugin=$KOTLIN_HOME
at the start of my file...mbonnin
11/13/2020, 3:01 PMkotlinc -script serialization.main.kts
manuallymbonnin
11/13/2020, 3:01 PMPiotr Krzemiński
06/27/2021, 5:44 AM