Search code examples
javaspring-bootrestjacksonspring-data-rest

What are the JSON mapper libraries supported by 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.


Solution

  • 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);
        }
    }