I know several issues have been raised on this topic, but why Jackson is still used to serialize and deserialize JSON whereas I've excluded it from everywhere : in the springboot application, in build.gradle.kts and set the preferred Json serializer in application.properties
When I "crash" this HTTP request for test driven purpose, I can see that the crash is due to jackson converter
class IronMaidenSourceApi {
companion object {
fun fetchIronMaidenSource(): ResponseEntity<DTOIronMaidenAPi> {
val uri = "http://localhost:3004/ironmaiden"
return RestTemplate().getForEntity(uri, DTOIronMaidenAPi::class.java) // <-- JACKSON still used here
}
}
}
error is :
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType
So how the hell can I totally exclude Jackson ?
Not in dependencies
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("org.postgresql:postgresql")
testImplementation("org.springframework.boot:spring-boot-starter-test")
implementation ("com.google.code.gson:gson:2.9.0")
}
preferred is set to GSon in application.properties
spring.jpa.open-in-view=false
server.port=7070
spring.http.converters.preferred-json-mapper=gson
exclude in main application
@SpringBootApplication(exclude = [JacksonAutoConfiguration::class])
CodePudding user response:
You need to exclude the transitive dependency like this:
dependencies {
implementation('commons-beanutils:commons-beanutils:1.9.4') {
exclude group: 'commons-collections', module: 'commons-collections'
}
Look at your dependency tree to see which dependencies are pulling it in and exclude it from each.