addamsson
04/26/2020, 3:40 PMimport kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
@Serializable
data class User(
val name: String
)
val user = User("jon")
val json = Json(JsonConfiguration.Stable)
val jsonData = json.stringify(User.serializer(), user)
val result = json.parse(User.serializer(), jsonData)
require(user == result)
which I try to run in a script but I get the following error:
ERROR Unresolved reference: serializer
I guess the problem is that this works with `kotlinx.serialization`'s annotation processing feature. Is it possible to get this working in a script?
This is how I run it:
private fun evalFile(scriptFile: File): ResultWithDiagnostics<EvaluationResult> {
val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<TestScript> {
jvm {
dependenciesFromCurrentContext(wholeClasspath = true)
}
}
val evalConfig = createJvmEvaluationConfigurationFromTemplate<TestScript> {
jvm {
this.mainArguments.put(arrayOf("1"))
}
}
return BasicJvmScriptingHost().eval(scriptFile.toScriptSource(), compilationConfiguration, evalConfig)
}
ilya.chernikov
04/27/2020, 9:47 AMaddamsson
04/27/2020, 2:57 PM