【问题标题】:What are the JSON mapper libraries supported by Spring Boot? [closed]Spring Boot 支持的 JSON 映射器库有哪些? [关闭]
【发布时间】:2021-02-04 19:14:09
【问题描述】:

Jackson 库是 Spring Boot 的默认集成 JSON 映射器库。我想知道还有哪些其他库可用或与 Spring Boot 集成,以及如何在我们的 Spring Boot 应用程序中实现它们。

【问题讨论】:

    标签: java spring-boot rest jackson spring-data-rest


    【解决方案1】:

    Spring boot 已经集成了 3 个 json mapper api

    • 杰克逊(默认)
    • 格森
    • JSON-B

    如果我们想使用例如 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 2014-12-29
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      相关资源
      最近更新 更多