We are trying to migrate on of our projects from JDK 11 to JDK 17. But out Kotlin version is even older! The application is using Kotlin 1.4.0 everywhere. So during the migration we decided to upgrade our Kotlin too.
So when I updated the JAR dependency in my pom file from 1.4.0 to 2.0.21, a class does like the change and is throwing an exception like this:
[ERROR] C:/Users/sam2004/git/app/develop/app-common/src/main/java/com/trial/app/ui/util/CacheConfig.kt:[53,64] Cannot access 'constructor(reflectionCacheSize: Int = ..., nullToEmptyCollection: Boolean = ..., nullToEmptyMap: Boolean = ..., nullIsSameAsDefault: Boolean = ..., singletonSupport: SingletonSupport = ..., strictNullChecks: Boolean = ..., useKotlinPropertyNameForGetter: Boolean = ..., useJavaDurationConversion: Boolean = ...): KotlinModule': it is private in 'com/fasterxml/jackson/module/kotlin/KotlinModule'.
The dependencies in question are:
<!-- .fasterxml.jackson.module/jackson-module-kotlin -->
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.18.1</version>
</dependency>
<!-- .jetbrains.kotlin/kotlin-stdlib-jdk8 -->
<dependency>
<groupId>.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>2.0.21</version>
</dependency>
I can see the error coming from the Jackson jar.
The line of code that is causing the problem is:
private val mapper = ObjectMapper().apply { registerModule(KotlinModule()) }
Is there a solution to this? Or do I just have to fall back to the older version because this might lead to a lot of code changes?
We are trying to migrate on of our projects from JDK 11 to JDK 17. But out Kotlin version is even older! The application is using Kotlin 1.4.0 everywhere. So during the migration we decided to upgrade our Kotlin too.
So when I updated the JAR dependency in my pom file from 1.4.0 to 2.0.21, a class does like the change and is throwing an exception like this:
[ERROR] C:/Users/sam2004/git/app/develop/app-common/src/main/java/com/trial/app/ui/util/CacheConfig.kt:[53,64] Cannot access 'constructor(reflectionCacheSize: Int = ..., nullToEmptyCollection: Boolean = ..., nullToEmptyMap: Boolean = ..., nullIsSameAsDefault: Boolean = ..., singletonSupport: SingletonSupport = ..., strictNullChecks: Boolean = ..., useKotlinPropertyNameForGetter: Boolean = ..., useJavaDurationConversion: Boolean = ...): KotlinModule': it is private in 'com/fasterxml/jackson/module/kotlin/KotlinModule'.
The dependencies in question are:
<!-- https://mvnrepository/artifact/com.fasterxml.jackson.module/jackson-module-kotlin -->
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.18.1</version>
</dependency>
<!-- https://mvnrepository/artifact/.jetbrains.kotlin/kotlin-stdlib-jdk8 -->
<dependency>
<groupId>.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>2.0.21</version>
</dependency>
I can see the error coming from the Jackson jar.
The line of code that is causing the problem is:
private val mapper = ObjectMapper().apply { registerModule(KotlinModule()) }
Is there a solution to this? Or do I just have to fall back to the older version because this might lead to a lot of code changes?
Share Improve this question asked Nov 19, 2024 at 15:09 hell_storm2004hell_storm2004 1,6055 gold badges46 silver badges77 bronze badges 1 |1 Answer
Reset to default 1According to the documentation, one of the following should work:
val mapper = jacksonObjectMapper()
val mapper = ObjectMapper().registerKotlinModule()
val mapper = jsonMapper {
addModule(kotlinModule())
}
(note the lower case kotlinModule()
)
private val mapper = ObjectMapper().registerKotlinModule()
and it seems to have made the exception go away. But without them mentioning the old and new, its very hard for us Kotlin new guys to make sense of whether what I did was correct or not. I think I will ask on the wiki on that page you mentioned. Thanks for the nudge though. It was of great help. If I get a solution from there, I will mention it here. – hell_storm2004 Commented Nov 19, 2024 at 15:21