KotlinSpring BootJackson谷歌gson. Jacshon仍然使用

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

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

  1. class IronMaidenSourceApi {
  2. companion object {
  3. fun fetchIronMaidenSource(): ResponseEntity<DTOIronMaidenAPi> {
  4. val uri = "http://localhost:3004/ironmaiden"
  5. return RestTemplate().getForEntity(uri, DTOIronMaidenAPi::class.java) // <-- JACKSON still used here
  6. }
  7. }
  8. }

错误为:

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

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

不在依赖项中

  1. dependencies {
  2. implementation("org.springframework.boot:spring-boot-starter-data-jpa")
  3. implementation("org.springframework.boot:spring-boot-starter-web")
  4. implementation("org.jetbrains.kotlin:kotlin-reflect")
  5. implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
  6. developmentOnly("org.springframework.boot:spring-boot-devtools")
  7. runtimeOnly("org.postgresql:postgresql")
  8. testImplementation("org.springframework.boot:spring-boot-starter-test")
  9. implementation ("com.google.code.gson:gson:2.9.0")
  10. }

application.properties中首选设置为GSon

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

在主应用程序中排除

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

qxsslcnc1#

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

  1. dependencies {
  2. implementation('commons-beanutils:commons-beanutils:1.9.4') {
  3. exclude group: 'commons-collections', module: 'commons-collections'
  4. }

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

相关问题