Describe the bug
I was able to work well with Kotlin version 1.3.61 but now I am getting crash with Kotlin version 1.3.70
Caused by: java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Lkotlinx/serialization/internal/GeneratedSerializer;I)V in class Lkotlinx/serialization/internal/SerialClassDescImpl; or its super classes (declaration of 'kotlinx.serialization.internal.SerialClassDescImpl' appears in /path)
To Reproduce
Create these classes:
@Serializable
data class PolygonResponse(
val maxSpeed: Int?,
val polygons: List<Polygons?>
)
@Serializable
data class Polygons(
val baseCapacity: Int?,
val distanceToPolygon: Int?,
val polygon: List<Polygon?>
)
md5-10b8b0d6da3143b73ab0c5327da932db
@Serializable(with = PolygonSerializer::class)
data class Polygon(
val coordinates: List<Double>
)
internal object PolygonSerializer : KSerializer<Polygon> {
private val serializer = ArrayListSerializer(Double.serializer())
override val descriptor: SerialDescriptor = StringDescriptor.withName("Polygon")
override fun serialize(encoder: Encoder, obj: Polygon) {
encoder.encode(serializer, obj.coordinates)
}
override fun deserialize(decoder: Decoder): Polygon {
return Polygon(decoder.decode(serializer))
}
}
Expected behavior
Serialization should work properly.
Environment
It's completely broken.
To verify just bump this:
https://github.com/Kotlin/kotlinx.serialization/blob/530ee1d8a1ec615359d2e724e563603622173b3a/integration-test/gradle.properties#L5
to .70 and 23 out of 25 test fail.
Thanks @PaulWoitaschek for the information. However, it is working with 1.3.61, too. Why?
kotlinx-serialization depends heavily on the compiler version (on the plugin bundled into compiler, actually), 0.14.0 is not compatible with 1.3.70.
We will release 0.20.0 today and think out how to improve diagnostics here
@qwwdfsad could you add some checks in the koltinx-serialization plugin ? Ideally detect incompatible versions and fail the build ? Or at least put a warning if the kotlin version is ahead of the one that the plugin supports ?
Version 0.20.0, which is compatible with 1.3.70, is now published on JCenter and will be available on Maven Central soon. Check out the release notes: https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md#0200--2020-03-04
Thank you.
If you're still having problems, try clean and build your project.
It should be getting the latest org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0.
Please note, I have just updated the plugin and I can confirm this issue has been fixed for my case. Thanks all again.
~Still has this problem with Kotlin version: [1.3.70], Library version: [0.20.0].~
I forgot to bump the version of kotlin gradle plugin in the /buildSrc/build.gradle.
Everything works fine now.
Most helpful comment
kotlinx-serializationdepends heavily on the compiler version (on the plugin bundled into compiler, actually), 0.14.0 is not compatible with 1.3.70.We will release 0.20.0 today and think out how to improve diagnostics here