KotlinSpring BootJackson谷歌gson. Jacshon仍然使用

vlurs2pr  于 2022-11-06  发布在  Kotlin
关注(0)|答案(1)|浏览(141)

我知道在这个主题上已经提出了一些问题,但是为什么Jackson仍然用于序列化和反序列化JSON,而我却将其排除在所有地方:在springboot应用程序的build.gradle.kts中,并在application.properties中设置首选的Json串行化程序
当我出于测试驱动的目的“崩溃”这个HTTP请求时,我可以看到崩溃是由于Jackson转换器造成的

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
        }
    }
}

错误为:

at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType

那我怎么才能完全排除Jackson呢

不在依赖项中

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")
}

application.properties中首选设置为GSon

spring.jpa.open-in-view=false
server.port=7070
spring.http.converters.preferred-json-mapper=gson

在主应用程序中排除

@SpringBootApplication(exclude = [JacksonAutoConfiguration::class])
qxsslcnc

qxsslcnc1#

您需要排除传递依赖项,如下所示:

dependencies {
implementation('commons-beanutils:commons-beanutils:1.9.4') {
    exclude group: 'commons-collections', module: 'commons-collections'
}

查看您的依赖关系树,以查看哪些依赖关系正在将其拉入并从每个依赖关系树中排除。

相关问题