Jackson 2 KotlinModule cannot be cast to Jackson 3 JacksonModule
Describe the bug Spring Cloud Function Context 5.0.0:
ContextFunctionCatalogAutoConfiguration tries to cast Jackson 2's com.fasterxml.jackson.module.kotlin.KotlinModule" to Jackson 3's tools.jackson.databind.JacksonModule in ContextFunctionCatalogAutoConfiguration:268 resulting in
…
Caused by: java.lang.ClassCastException: class com.fasterxml.jackson.module.kotlin.KotlinModule cannot be cast to class tools.jackson.databind.JacksonModule (com.fasterxml.jackson.module.kotlin.KotlinModule and tools.jackson.databind.JacksonModule are in unnamed module of loader 'app')
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$JsonMapperConfiguration.jackson(ContextFunctionCatalogAutoConfiguration.java:270)
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$JsonMapperConfiguration.jsonMapper(ContextFunctionCatalogAutoConfiguration.java:229)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:155)
... 51 more
Sample Any Kotlin application using Spring Cloud Function Context 5.0.0 should fail.
I have the same issue, is it as simple as changing the package here to tools.jackson ?
This blocks upgrading to Spring Boot 4 unfortunately
FWIW I forked the repo and made the suggested change and it works locally in my Kotlin project I'll raise a PR - just jumping through necessary hoops internally
We ran into the same issue. Any workarounds or plans to be fixed without forking the codebase?
try to remove the jackson 2 kotlin module from your classpath and add the jackson 3 kotlin module manually for now.
If that's not possible for whatever reason you can override completely the JacksonMapper by redoing what they are configuring:
import org.springframework.cloud.function.json.JacksonMapper
import org.springframework.cloud.function.json.JsonMapper
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import tools.jackson.core.StreamReadFeature
import tools.jackson.databind.DeserializationFeature
import tools.jackson.databind.SerializationFeature
@Configuration
class JacksonMapperConfiguration {
// TODO: to remove when this issue is fixed
// https://github.com/spring-cloud/spring-cloud-function/issues/1319
@Bean
fun cloudFunctionJsonMapper(builder: tools.jackson.databind.json.JsonMapper.Builder): JsonMapper {
val jsonMapper =
builder
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false)
.configure(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION, false)
.build()
return JacksonMapper(jsonMapper)
}
}