constructor - Kotlin Upgrade Issue With KotlinModule Being Private - Stack Overflow

We are trying to migrate on of our projects from JDK 11 to JDK 17. But out Kotlin version is even older

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
  • @Marvin It does give me an example of what I am looking for, I changed the code like the first example 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
Add a comment  | 

1 Answer 1

Reset to default 1

According 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())

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742420353a4440558.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信