b

    bendb

    2 years ago
    This is probably a layer 8 problem, but I'm stumped. I'm attempting to use kotlinx.serialization without taking a kotlin-reflect dependency in a multiplatform project. I'm trying to do a basic sanity check in a JVM unit test that this works, but am getting a
    NoClassDefFoundError
    in
    Json.<clinit>
    , which is indirectly trying to look up
    KPackage
    , a kotlin-reflect type. The test passes if I add a
    kotlin-reflect
    dependency. Is it the case that json support requires kotlin-reflect?
    stack trace showing the error:
    kotlin/reflect/KPackage
    java.lang.NoClassDefFoundError: kotlin/reflect/KPackage
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:264)
    	at kotlin.jvm.internal.Reflection.<clinit>(Reflection.java:26)
    	at kotlinx.serialization.json.JsonKt.<clinit>(Json.kt:216)
    	at kotlinx.serialization.json.Json.<init>(Json.kt:63)
    	at kotlinx.serialization.json.Json.<init>(Json.kt:62)
    	at kotlinx.serialization.json.Json.<clinit>(Json.kt:160)
    ...
    Nikky

    Nikky

    2 years ago
    can you show code or reproduce in a minimal sample,?also sanitycheck versions of kotlin and serialization and plugins ?
    b

    bendb

    2 years ago
    Sure. Kotlin is 1.3.50, serialization is 0.13.0. I'll paste the snippet in a second.
    @Serializable
    data class BasicData(val eventType: Int)
    
    class SerializationTests {
      @Test
      fun basicTest() {
        Json.stringify(BasicData.serializer(), BasicData(5)) shouldBe """{"eventType":5}"""
      }
    }
    the error happens before
    stringify
    is ever called - it's raised during class loading of
    kotlinx.serialization.json.Json
    Fudge

    Fudge

    2 years ago
    I believe this is a bug that is fixed in the next release https://github.com/Kotlin/kotlinx.serialization/issues/549
    b

    bendb

    2 years ago
    I kind of thought so at first, but the responsible code in
    Json.kt
    hasn't changed.
    Nikky

    Nikky

    2 years ago
    i use kotlin 1.3.50 and serialization 0.12.0 and it works fine, not sure why i did not upgrade, but it was one of those bugs
    m

    Marc Knaup

    2 years ago
    How did you manage to do that? 😄
    KPackage
    has been removed in Kotlin 1.0.1 😮 Most likely cause is a rift in the space-time continuum. Did a really old Kotlin dependency sneak in somehow?
    j

    JoakimForslund

    2 years ago
    I'm doing the same 😄