【发布时间】:2021-02-04 19:14:09
【问题描述】:
Jackson 库是 Spring Boot 的默认集成 JSON 映射器库。我想知道还有哪些其他库可用或与 Spring Boot 集成,以及如何在我们的 Spring Boot 应用程序中实现它们。
【问题讨论】:
标签: java spring-boot rest jackson spring-data-rest
Jackson 库是 Spring Boot 的默认集成 JSON 映射器库。我想知道还有哪些其他库可用或与 Spring Boot 集成,以及如何在我们的 Spring Boot 应用程序中实现它们。
【问题讨论】:
标签: java spring-boot rest jackson spring-data-rest
Spring boot 已经集成了 3 个 json mapper api
如果我们想使用例如 Gson,那么只需在你的 pom 文件中添加以下依赖项
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
但我们已经默认实现了 Jackson,我们可以使用 maven 或务实地排除它
使用 maven
在 pom 文件中,在 excludes 标签下添加 starter-json 的排除
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</exclusion>
</exclusions>
以编程方式
@SpringBootApplication(exclude = {JacksonAutoConfiguration.class})
public class GsonSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(GsonSpringBootApplication.class, args);
}
}
【讨论】: