FasterXML / jackson-module-kotlin

Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Apache License 2.0
1.12k stars 175 forks source link

kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Cannot create type for an unsupported classifier: class kotlin.Unit (Kotlin reflection is not available) (class kotlin.jvm.internal.ClassReference) #614

Closed yoku0206 closed 1 year ago

yoku0206 commented 1 year ago

I don't know what happend

kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Cannot create type for an unsupported classifier: class kotlin.Unit (Kotlin reflection is not available) (class kotlin.jvm.internal.ClassReference)
        at kotlin.reflect.full.KClassifiers.createType(KClassifiers.kt:48) ~[YokuAPIPlus-1.0-all.jar:?]
        at kotlin.reflect.full.KClassifiers.createType$default(KClassifiers.kt:42) ~[YokuAPIPlus-1.0-all.jar:?]
        at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector.<clinit>(KotlinAnnotationIntrospector.kt:218) ~[YokuAPIPlus-1.0-all.jar:?]
        at com.fasterxml.jackson.module.kotlin.KotlinModule.setupModule(KotlinModule.kt:121) ~[YokuAPIPlus-1.0-all.jar:?]
        at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:879) ~[YokuAPIPlus-1.0-all.jar:?]
        at com.fasterxml.jackson.module.kotlin.ExtensionsKt.registerKotlinModule(Extensions.kt:41) ~[YokuAPIPlus-1.0-all.jar:?]
        at me.yoku.yokuapiplus.YokuAPIPlus.onEnable(YokuAPIPlus.kt:25) ~[YokuAPIPlus-1.0-all.jar:?]
cowtowncoder commented 1 year ago

Without more information on how to reproduce the problem, no one knows what happened... :-D

yoku0206 commented 1 year ago
// build.gradle.kts
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.0")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.0")
implementation("com.fasterxml.jackson.core:jackson-databind:2.14.0")
val mapper = ObjectMapper(YAMLFactory()).registerKotlinModule()

This is my code, i saw this code form Usage and use it, but it only give me this error

cowtowncoder commented 1 year ago

That is not code showing any failure, it's just initialization. Closing for now; may be reopened with reproduction.

abhilashmandaliya commented 1 year ago

@yoku0206 I also hit the same error in my project with apache pulsar. In my case, the problem was the order of class loading. Pulsar was bringing the kotlin-stdlib 1.4.32 where as Jackson wanted the higher version of kotlin-stdlib. See if that is the case for you also. Some of your libraries might have a dependency on a different version of kotlin-stdlib and that might be getting loaded first and that version is different than the one Jackson requires.