admin管理员组文章数量:1336659
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()
)
本文标签: constructorKotlin Upgrade Issue With KotlinModule Being PrivateStack Overflow
版权声明:本文标题:constructor - Kotlin Upgrade Issue With KotlinModule Being Private - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742420352a2471532.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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