Configure Spring Boot with Gson or Jackson or JSON-B

In this short article, we will discuss how to configure Spring Boot to work with different JSON mapping libraries.
Spring Boot provides integration with three JSON mapping libraries:
  • Gson
  • Jackson
  • JSON-B
Jackson is the preferred and default library.

Let's discuss each of the above JSON library integration with Spring boot.

1. Jackson

Spring Boot uses Jackson by default for serializing and deserializing request and response objects in your REST APIs.
Auto-configuration for Jackson is provided and Jackson is part of spring-boot-starter-json. When Jackson is on the classpath an ObjectMapper bean is automatically configured. Several configuration properties are provided for customizing the configuration of the ObjectMapper.

2. Gson

Auto-configuration for Gson is provided. When Gson is on the classpath a Gson bean is automatically configured. Several spring.gson.* configuration properties are provided for customizing the configuration.
Let's deep dive and discuss how to use Gson in your spring boot projects.
If you want to use Gson instead of Jackson then it’s just a matter of adding Gson dependency in your pom.xml file and specifying a property in the file to tell Spring Boot to use Gson as your preferred JSON mapper.

Add Gson dependency

Open your pom.xml file and add the Gson dependency like so -
<!-- Include GSON dependency -->
Once you do that, Spring Boot will detect Gson dependency on the classpath and automatically create a Gson bean with sensible default configurations. You can also autowire Gson in your spring components directly like so -
private Gson gson;

Set the preferred JSON mapper to GSON

You can now ask Spring Boot to use Gson as your preferred JSON mapper by specifying the following property in the file -
# Preferred JSON mapper to use for HTTP message conversion.
That’s all you need to do to force Spring Boot to use Gson instead of Jackson.


JSON Binding (JSON-B) is the new Java EE specification for converting JSON messages to Java Objects and back.
Auto-configuration for JSON-B is provided. When the JSON-B API and implementation are on the classpath a Jsonb bean will be automatically configured. The preferred JSON-B implementation is Apache Johnzon for which dependency management is provided.
If you want to know more about JSON-B itself, you can visit the official website -

Add JSON-B dependency

Let's see how to use JSON-B in your spring boot projects. It is very simple. You need to add the required Maven dependencies:

Set the preferred JSON mapper to JSON-B

You need to choose the preffered-json-mapper setting to make sure that JSON-B is chosen. You may get Gson or Jackson on the classpath and then you can’t be sure how the autoconfiguration will work without this setting:
That’s all you need to do to force Spring Boot to use JSON-B instead of Jackson.

Related Spring Boot Articles

Check out all spring boot articles, guides, and tutorials at Top Spring Boot Tutorials

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours

Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course