Home > Net >  Micronaut @SerdeImport annotation not working with Kotlin
Micronaut @SerdeImport annotation not working with Kotlin

Time:01-25

I am working on developing an application using Micronaut framework with Kotlin language. However, I am facing an issue where @SerdeImport annotation is not being recognized when using Micronaut with Kotlin. I am getting the below error even after using the @SerdeImport annotation.

No serializable introspection present for type MarketSnapshot B. 
Consider adding Serdeable. Serializable annotate to type MarketSnapshot B.
Alternatively if you are not in control of the project's source code, 
you can use @SerdeImport(MarketSnapshot.class) to enable serialization of this type."}]}}

The same annotation works fine when using Java, however, it fails with the Kotlin program. Below are the micronaut kotlin related dependencies that are used in build.gradle file

annotationProcessor 'io.micronaut:micronaut-inject-java'
annotationProcessor 'io.micronaut:micronaut-http-validation'
annotationProcessor 'io.micronaut.openapi:micronaut-openapi'
annotationProcessor 'io.micronaut.serde:micronaut-serde-processor'

kapt 'io.micronaut:micronaut-http-validation'
kapt 'io.micronaut:micronaut-inject-java'
implementation 'org.jetbrains.kotlin:kotlin-reflect:${kotlin}'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin}'
implementation 'io.micronaut.kotlin:micronaut-kotlin-runtime'
implementation 'io.micronaut.serde:micronaut-serde-jackson'
implementation 'io.micronaut:micronaut-management'
implementation 'io.micronaut:micronaut-http-client'
implementation 'io.micronaut:micronaut-jackson-databind'
implementation 'io.micronaut:micronaut-validation'
implementation 'jakarta.annotation:jakarta.annotation-api'

CodePudding user response:

Do you have something like this in your build.gradle:

configurations.all {
    resolutionStrategy.dependencySubstitution {
        substitute(module("io.micronaut:micronaut-jackson-databind"))
            .using(module("io.micronaut.serde:micronaut-serde-jackson:1.5.0"))
    }
}

Also, think annotationProcessor 'io.micronaut.serde:micronaut-serde-processor' should be kapt("io.micronaut.serde:micronaut-serde-processor")

Micronaut Launch has a diff view to show the changes when adding a new feature.

For example: Micronaut Kotlin with serialization-jackson diff shows this for the changes to the build file:

 dependencies {
     kapt("io.micronaut:micronaut-http-validation")
     kapt("io.micronaut.serde:micronaut-serde-processor")
     implementation("io.micronaut:micronaut-http-client")
-    implementation("io.micronaut:micronaut-jackson-databind")
     implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
     implementation("io.micronaut.serde:micronaut-serde-jackson")
     implementation("jakarta.annotation:jakarta.annotation-api")
     implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
     implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
@@ -57,3  58,12 @@
         annotations("com.example.*")
     }
 }
 
 
 
 configurations.all {
     resolutionStrategy.dependencySubstitution {
         substitute(module("io.micronaut:micronaut-jackson-databind"))
             .using(module("io.micronaut.serde:micronaut-serde-jackson:1.5.0"))
     }
 }
  • Related