You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importkotlinx.serialization.Serializableimportkotlinx.serialization.json.Jsonimportkotlinx.serialization.encodeToString
@Serializable
data classFoo(vala:Int, valb:String)
val str:String=Json.encodeToString(Foo(42, "test"))
println(str)
val foo:Foo=Json.decodeFromString<Foo>("{\"a\":42,\"b\":\"test\"}")
println(foo)
This is a bit fancy, just wanted to set the CLASSPATH and avoid constantly invoking Gradle but still have dependencies included for the script. The problem is that I keep getting this error:
kotlinx.serialization.SerializationException: Serializer for class 'Foo' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
at kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform.common.kt:91)
at kotlinx.serialization.internal.PlatformKt.platformSpecificSerializerNotRegistered(Platform.kt:28)
at kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:134)
at kotlinx.serialization.SerializersKt.serializer(Unknown Source)
...
Even though @Serializable annotation is added for the class.
Environment
Kotlin version: Kotlin version 1.9.255-SNAPSHOT (JRE 21+35-nixos)
Library version: 1.6.0
Kotlin platforms: JVM
Gradle version: 8.4
The text was updated successfully, but these errors were encountered:
The answer to your question is in the second part of the exception message:
and that the serialization compiler plugin is applied.
Given that you're invoking the compiler manually, passing -Xplugin argument to it is required. Serialization compiler plugin is a separate jar that is not a part of runtime. You can find it using these coordinates: https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-serialization-compiler-plugin or in ${KOTLIN_HOME}/lib/kotlin-serialization-compiler-plugin.jar
Describe the bug
I have a simple Kotlin script (
foo.kts
):I start it like this:
kotlin -classpath "$(./gradlew -q printDependenciesClasspath)" ./test-kotlin-script-json.kts
Where in Gradle I have this task:
This is a bit fancy, just wanted to set the CLASSPATH and avoid constantly invoking Gradle but still have dependencies included for the script. The problem is that I keep getting this error:
Even though
@Serializable
annotation is added for the class.Environment
Kotlin version 1.9.255-SNAPSHOT (JRE 21+35-nixos)
The text was updated successfully, but these errors were encountered: