Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Compare Gson and Jackson for a new Spring Boot service. Which would you choose and why?

For a new Spring Boot service, we would choose Jackson. Spring Boot already uses it for HTTP message conversion, it has rich annotations, modules for java.time, Kotlin and records, polymorphic type support and fast streaming, and it is actively developed. Gson is small and simple, using reflection on fields, but it is in maintenance mode and has no built-in java.time support; Boot can be switched to it with a property (spring.mvc.converters.preferred-json-mapper=gson, but check your version for the name), which is worth doing only for a concrete reason such as an existing Gson-based library or shared Android code.

Why this question is asked

Choosing a JSON library sounds like a small decision, but it shapes every API the service exposes: how dates look, whether nulls appear, how errors read, and how much configuration the team maintains. Interviewers ask this comparison to see whether we choose on facts about the framework and the libraries rather than habit. In this answer, we will see what Spring Boot already does with JSON, compare the two libraries on the points that matter in a service, look at what switching to Gson involves, and finish with when Gson is still the right choice.

1What Spring Boot Already Does

In a Spring Boot web application, every @RestController method that returns an object has its result converted to JSON by an HttpMessageConverter, and request bodies are converted the other way. With the web starter, Boot puts Jackson on the classpath, creates an ObjectMapper with sensible defaults, such as writing dates as ISO strings rather than numbers and not failing on unknown properties, registers modules it finds, and lets us tune it with spring.jackson.* properties or a customizer bean. The same ObjectMapper is used by RestClient, WebClient, Spring Kafka's JSON serializers and the actuator endpoints.

So choosing Jackson costs nothing extra: it is already there, already configured, and used consistently across the framework. Choosing Gson means adding a second library and making sure every one of those places uses it, or living with two JSON stacks whose defaults differ.

2Comparing the Two Libraries

Beyond integration, the libraries differ in features. Jackson has a large annotation set, @JsonProperty, @JsonIgnore, @JsonCreator, @JsonValue, @JsonInclude, @JsonView and more, so most mapping needs are declarative. Its module system covers java.time (JavaTimeModule, which Boot registers), Kotlin, records and many third-party types, and it supports polymorphic types with @JsonTypeInfo and @JsonSubTypes. Its streaming API and data binding are among the fastest in Java, and it is actively developed; Spring Boot 4 moves to Jackson 3, which renames packages, so check your version.

Gson's strength is simplicity: one small jar, no required configuration, and reflection on fields, so plain classes work without annotations. But it is in maintenance mode, which means fixes without large new features, it has no built-in support for java.time types, so each team writes adapters, and polymorphism requires custom code. For a service that will live for years and grow, those gaps add up.

Gson and Jackson for a Spring Boot service
AspectJacksonGson
Spring Boot integrationdefault, auto-configuredoptional, needs a property
Reads properties fromgetters and fieldsfields only
Nulls by defaultwrittenomitted
java.timeJavaTimeModule, registered by Bootcustom TypeAdapters needed
Polymorphism@JsonTypeInfo, @JsonSubTypescustom TypeAdapterFactory
Project statusactively developedmaintenance mode
Size and simplicityseveral jars, many featuresone small jar, minimal API

3A Small Example of the Difference

The same record shows the practical gap.

Java
record Shipment(String id, Instant shippedAt, String note) { }
Shipment s = new Shipment("S1", Instant.parse("2026-11-05T10:15:30Z"), null);
// Jackson, the ObjectMapper Spring Boot configures
objectMapper.writeValueAsString(s);
// {"id":"S1","shippedAt":"2026-11-05T10:15:30Z","note":null}
// Gson, defaults
new Gson().toJson(s);
// fails on Java 17+ for the Instant field until a TypeAdapter is registered;
// with an adapter: {"id":"S1","shippedAt":"2026-11-05T10:15:30Z"} (note omitted)

With Jackson, the service gets a sensible contract with zero code. With Gson, we write and maintain an adapter for each java.time type, and the null handling differs from what other Spring services in the company probably produce.

4Switching Spring Boot to Gson

If we do need Gson for HTTP, Boot supports it. With Gson on the classpath, Boot auto-configures a Gson bean, and a property tells the MVC converters to prefer it: spring.mvc.converters.preferred-json-mapper=gson in recent versions, while some versions used spring.http.converters.preferred-json-mapper, so check your version for the exact name. spring.gson.* properties configure the instance.

Properties
# application.properties
spring.mvc.converters.preferred-json-mapper=gson # check the property name for your Boot version
spring.gson.serialize-nulls=true
spring.gson.field-naming-policy=lower_case_with_underscores

Notice that this affects only HTTP message conversion. Other parts of the stack, such as some client and messaging integrations, may still use Jackson, so the service can end up with two libraries anyway, which is one more reason the switch needs a real justification.

5When Gson Is Still the Right Choice

There are concrete reasons to pick Gson. If the service must use a shared client library whose models and adapters are built on Gson, keeping one library avoids duplicating every adapter. If the service shares model code with an Android app, where Gson is common and small size matters, one library on both sides can be simpler. And for a tiny utility outside Spring, Gson's zero-configuration simplicity is attractive.

Without such a reason, we choose Jackson: it is already integrated, it is actively developed, and it handles modern Java types out of the box. The decision rule is "Jackson unless there is a concrete reason", and the reason should be written down in the service's design notes.

6Follow-up questions

Is Jackson slower to start or heavier?

Jackson is a few jars and builds serializers lazily, so the startup and memory cost is small for a typical service, and Spring Boot loads it anyway. Its runtime throughput is generally at least as good as Gson's. Differences only matter in extreme cases, which should be measured rather than assumed.

What about JSON-B?

JSON-B is the Jakarta EE standard API for JSON binding, with Yasson as the usual implementation, and Spring Boot can use it as well. It makes sense in a Jakarta EE environment; in a Spring Boot service it has the same drawback as Gson, a second stack next to the Jackson the framework expects.

Can Jackson behave like Gson if we need the same output?

Mostly, yes. We can set field visibility, exclude nulls with an inclusion rule, and ignore unknown properties, which together reproduce Gson's main defaults. That is useful when migrating from Gson while keeping the JSON identical.

7Conclusion

In this answer, we saw that Spring Boot already configures Jackson for HTTP message conversion and much of the framework, so choosing Jackson costs nothing and keeps one stack. Jackson also offers rich annotations, modules for java.time, Kotlin and records, polymorphic types and fast streaming, and is actively developed, while Gson is small and simple but in maintenance mode and without java.time support. Boot can switch to Gson with a converter property, but we do that only for a concrete reason such as a Gson-based shared library or Android code.

What to say in the interviewAbout 80 seconds aloud

Open with

For a new Spring Boot service I would choose Jackson unless there is a concrete reason not to. The biggest reason is integration: Boot already uses Jackson for HTTP message conversion, auto-configures an ObjectMapper with good defaults like ISO dates and tolerance of unknown properties, and the same mapper is used by clients, messaging and actuator, so choosing Jackson means no second stack and no extra configuration.

Then, if they want more

Jackson is also feature-rich: annotations like @JsonProperty, @JsonCreator and @JsonInclude, modules for java.time, Kotlin and records, polymorphic types with @JsonTypeInfo, and a fast streaming API, and it is actively developed; Boot 4 moves to Jackson 3.

Gson is small and simple and works on fields without annotations, but it is in maintenance mode, has no built-in java.time support, so on modern Java you need adapters for Instant and LocalDate, and polymorphism needs custom code. Its defaults also differ, for example it omits nulls.

If I had to, I could switch Boot's converters to Gson with the preferred-json-mapper property, checking the exact property name for the Boot version, plus spring.gson settings. I would only do that for a concrete reason, such as depending on a Gson-based shared library or sharing models with an Android app.

About this answer

Last updated
12 November 2026
Versions it names
Java 17, Spring Boot 4
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Compare Gson and Jackson for a new Spring Boot service. Which would you choose and why?": https://scrivio-interview-library.netlify.app/java/json-libraries/7d526b4ab2/