https://kotlinlang.org logo
#gradle
Title
# gradle
o

Ola Adolfsson

07/24/2022, 8:30 AM
Hi! I’m trying to use kotlin.serialiazation in a gradle task in order to read a json file, modify it and save the file again. Open for other suggestions 🙂. It was working with groovy using JsonSluper. Is that possible? Existing and working code in Groovy.
Copy code
def file = new File(path)
def data = new JsonSlurper().parse(file)
data.types = "my new value"
def json = JsonOutput.prettyPrint(JsonOutput.toJson(data))
👌 2
@Chrimaeon How? 🙂 In my build.gradle.kts I’m trying to import
Copy code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import kotlinx.serialization.*
import kotlinx.serialization.json.*
But the compiler complains
Unresolved reference: serialization
c

Chrimaeon

07/24/2022, 9:06 AM
You have to add Kotlin.serialization plug-in to the classpath of the buildscript first
❤️ 1
o

Ola Adolfsson

07/24/2022, 9:07 AM
DOH!!…. @Chrimaeon THANKS 🙂
7 Views