英文:
What are the JSON mapper libraries supported by Spring Boot?
问题
The Jackson library is the default integrated JSON mapper library with Spring Boot.
英文:
The Jackson library is the default integrated JSON mapper library with Spring Boot. I want to know what other libraries are available or integrated with Spring Boot, and how to implement them in our Spring Boot application.
答案1
得分: 1
Spring Boot已集成了3个JSON映射器API
- Jackson(默认)
- Gson
- JSON-B
如果我们想要使用Gson,只需在您的pom文件中添加以下依赖:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
但是默认情况下,我们已经实现了Jackson,我们可以使用Maven或编程方式进行排除
使用Maven
在pom文件中,在排除标签下添加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);
}
}
英文:
Spring boot has integrated with 3 json mapper api
- Jackson(default)
- Gson
- JSON-B
If we want to use for example Gson then simply add below dependency in your pom file
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
But we already have by default Jackson implemented which we can exclude either using maven or pragmatically
Using maven
In pom file add exclusion for starter-json under exclusions tag
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</exclusion>
</exclusions>
programmatically
@SpringBootApplication(exclude = {JacksonAutoConfiguration.class})
public class GsonSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(GsonSpringBootApplication.class, args);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论