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

java.lang.NoSuchMethodError: No direct method <init>(IZZILkotlin/jvm/internal/DefaultConstructorMarker;)V in class Lcom/fasterxml/jackson/module/kotlin/KotlinModule; or its super classes (declaration of 'com.fasterxml.jackson.module.kotlin.KotlinModule #282

Closed Praween closed 4 years ago

Praween commented 4 years ago

Hi,

Android Studio : 3.5.3

One of my project library is using, registerModules(KotlinModule()) as

private var objectMapper = ObjectMapper().apply {
            registerModules(KotlinModule())
            disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
            setSerializationInclusion(JsonInclude.Include.NON_NULL)
        }

using latest version of jackson-kotlin-module -2.10.1 from maven repository

After addition of above piece, my application crash on launch spitting in logcat as ,

Process: com.potreromed.accurynmonitor, PID: 1859 java.lang.NoSuchMethodError: No direct method (IZZILkotlin/jvm/internal/DefaultConstructorMarker;)V in class Lcom/fasterxml/jackson/module/kotlin/KotlinModule; or its super classes (declaration of 'com.fasterxml.jackson.module.kotlin.KotlinModule' appears in /data/app/com.potreromed.accurynmonitor-2/base.apk) at com.potreromed.phg.client.PhgClient$Builder.(PhgClient.kt:63) at com.potreromed.accurynmonitor.data.net.AcmMqtt.getMqttClient(AcmMqtt.kt:66) at com.potreromed.accurynmonitor.AccurynApplication$initPhgClient$1.run(AccurynApplication.kt:119) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)

function added in the library for json support,

buildscript {
    ext.kotlin_version = '1.3.61'
    ext.android_plugin_version = '3.5.3'
    ext.jacoco_version = '0.8.1'
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://repo.eclipse.org/content/repositories/paho-snapshots/" }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:$android_plugin_version"
        classpath "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
     }
}
allprojects {
    repositories {
        google()
        jcenter()
        // Set up a repository which looks for dependencies in the "libs" folder
        flatDir { dirs 'libs' }
    }
}

Tried googling, cleaned cache, rebuilding .... checking gradle app dependencies for the library conflict. So far nothing worked for me.

Regards, Praween

erika33 commented 4 years ago

Erikabarcenas599@gmail.com

frost13it commented 4 years ago

Duplicate of #279

cowtowncoder commented 4 years ago

Dup as per above: fix will be in 2.10.2 thanks to patch by @frost13it

Yochyo commented 3 years ago

Had the same problem with 2.11.3. Switching to version 2.10.2 fixed the issue.

nonproto commented 3 years ago

Had the same issue with 2.12.1 with a kotlin library that was being imported into a java spring boot app. Downgrading to 2.10.2 fixed it

patrykkrawczyk commented 3 years ago

This should be reopened as this is still a problem in 2.12.3 and 2.12.4 @cowtowncoder For anyone wanting to use a new version, try changing:

registerModule(KotlinModule()) // this
registerKotlinModule()         // to this
dinomite commented 3 years ago

@patrykkrawczyk I think you'll find that your application has multiple Jackson versions that are being hoisted by the build system. Look at the dependencies task in Gradle or dependency:tree in Maven.

This isn't a bug in jackson-module-kotlin 2.12.3 or 2.12.4, but rather an API change triggered in j-m-k 2.12, so a library built against a version prior to 2.12 but run with 2.12 or greater won't be able to find the method that it was built against.

strowk commented 2 years ago

@dinomite , could you point at exactly what was the breaking change in that module? I cannot see anything in https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.12 . Is there any migration guide?