SpringBoot 2.5.0 For Jackson Kotlin classes support please add "com.fasterxml.jackson.module: jackson-module-kotlin" to the classpath

Viewed 6159

This is now fixed with SpringBoot 2.5.1

Small question about a warning I am receiving please.

After the release of 2.5.0 of SpringBoot, I just did a version bump from 2.4.x to 2.5.0, without any code change.

Suddenly, on application start up, I am getting

kground-preinit] o.s.h.c.j.Jackson2ObjectMapperBuilder: For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath

The thing is, my Springboot all is not a Kotlin app, it is a Java app.

It has nothing Kotlin.

Furthermore, I am not even doing any explicit JSON parsing.

May I ask how I can disable, resolve this warning please?

3 Answers

Edit: Just upgrade to Spring Boot 2.5.1 where this is resolved.


Old answer below:

I managed to fix this for now by adding exclusions to my spring-boot-starter-security dependency which apparently defined this Kotlin dependency.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
        </exclusion>
    </exclusions>
</dependency>

There seems to be a solution here. The idea is to provide extra configuration for Jackson2ObjectMapperBuilderCustomizer. Sucks that a code change is required but there you have it.

This happens as builder checks if kotlin-runtime is present in classpath by simple:

if (KotlinDetector.isKotlinPresent())

So you should only to remove kotlin-runtime from your project dependencies tree. For example, org.springframework.boot:spring-boot-starter-security has transitive dependency to org.jetbrains.kotlin. Simple exclude that as:

exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'

Enjoy.

Related