Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How does Spring Boot configure Jackson's ObjectMapper, and how do you change a setting like the naming strategy?

Spring Boot's JacksonAutoConfiguration builds one ObjectMapper from a builder, applies Boot's defaults (for example, dates as ISO strings and unknown properties ignored), registers well-known modules such as java.time support, and adds every Module bean it finds. We change settings with spring.jackson.* properties, such as spring.jackson.property-naming-strategy=SNAKE_CASE, or in code with a Jackson2ObjectMapperBuilderCustomizer bean. Defining our own ObjectMapper bean replaces Boot's completely, so we lose all of that unless we build it from the same builder.

Why this question is asked

Almost every Spring Boot service turns Java objects into JSON and back, and nearly all of it goes through a single ObjectMapper that Boot created for us. When a team needs snake_case field names, a different date format or a custom module, the way they make the change decides whether the rest of Boot's configuration survives. Interviewers ask this because a wrong choice here, usually declaring a new ObjectMapper bean, is behind many confusing JSON bugs. In this answer, we will see how Boot builds the mapper, change the naming strategy with a property and with a customizer, register modules, and look at what happens when we define our own ObjectMapper. Spring Boot 4 moves to Jackson 3, and we will note where the names change.

1A Quick Recap: ObjectMapper and Where Spring Uses It

ObjectMapper is Jackson's main class. It reads JSON into Java objects (deserialization) and writes Java objects as JSON (serialization), and its configuration decides details such as field naming, date formats and what to do with unknown fields. In a Spring MVC application, the HTTP message converter for JSON uses an ObjectMapper for every @RequestBody and @ResponseBody, and the same mapper is used by RestClient, WebClient codecs and many other integrations when Boot configures them.

So there is one mapper that matters most, the one Boot creates, and it is a bean we can inject anywhere with a constructor parameter of type ObjectMapper.

2How JacksonAutoConfiguration Builds the Mapper

Boot does not create the ObjectMapper directly. It first creates a Jackson2ObjectMapperBuilder bean, Spring's fluent builder for mappers, and lets a list of customizers adjust it. The most important customizer is Boot's own, which applies the spring.jackson.* properties and Boot's defaults: WRITE_DATES_AS_TIMESTAMPS and WRITE_DURATIONS_AS_TIMESTAMPS off, so dates become ISO strings, and, inherited from Spring's builder, FAIL_ON_UNKNOWN_PROPERTIES and DEFAULT_VIEW_INCLUSION off. The builder also registers well-known modules found on the classpath, such as the java.time module, the Jdk8 module for Optional and the parameter names module, and it registers every bean of type Module from the context.

Finally, Boot calls builder.build() and exposes the result as the primary ObjectMapper bean, but only if we have not defined one ourselves. That condition is the key to the last section.

Step throughHow Boot builds its ObjectMapper
  1. spring.jackson.* propertiesnaming strategy, features, date format, inclusion
  2. CustomizersBoot's standard one first, then our Jackson2ObjectMapperBuilderCustomizer beans
  3. Jackson2ObjectMapperBuilderdefaults plus well-known modules and Module beans
  4. ObjectMapper beancreated only if we did not define one
  5. Users of the mapperMVC message converter, RestClient, WebClient, our code

5 layers, from the top down. Step through them one at a time.

Every layer adds to the one below; defining an ObjectMapper bean skips the whole stack.

3Changing the Naming Strategy With a Property

For settings that Boot exposes as properties, a property is the simplest and most visible choice. The naming strategy decides how Java property names map to JSON names, and SNAKE_CASE turns orderId into order_id.

Java
# application.properties
spring.jackson.property-naming-strategy=SNAKE_CASE
spring.jackson.default-property-inclusion=non_null
spring.jackson.serialization.indent-output=false
// record OrderView(long orderId, String customerName, String couponCode) {}
// new OrderView(7, "Ana", null)
// before: {"orderId":7,"customerName":"Ana","couponCode":null}
// after: {"order_id":7,"customer_name":"Ana"} couponCode omitted by non_null

Notice that the property also changes how requests are read: a client must now send order_id, and orderId would be an unknown property, silently ignored because of Boot's defaults. A naming change is therefore a breaking change for every client of the service, which is why it should be decided once at the start, not halfway through.

4Changing Settings in Code With a Customizer

Some settings have no property, or we want them to be compiled and reviewed with the code. For those we declare a Jackson2ObjectMapperBuilderCustomizer bean. Boot passes the shared builder to every customizer before building the mapper, so our change is added on top of Boot's configuration instead of replacing it.

Java
@Configuration
class JsonConfig {
@Bean
Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
return builder -> builder
.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
.featuresToEnable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES) // {"qty":null} into int fails
.serializationInclusion(JsonInclude.Include.NON_NULL);
}
@Bean
Module moneyModule() { // any Module bean is registered automatically
return new SimpleModule("money").addSerializer(Money.class, new MoneySerializer());
}
}

Notice that we never touch the ObjectMapper itself. Customizers can be ordered with @Order when two of them change the same setting; Boot's standard customizer, which applies the properties, has order 0, so a customizer with a higher order runs after it and wins. In Spring Boot 4, with Jackson 3, the equivalent builder is a JsonMapper.Builder and the customizer type is JsonMapperBuilderCustomizer; the properties keep their spring.jackson prefix, but check the Boot 4 documentation for any renamed keys.

5What Happens When We Define Our Own ObjectMapper

The tempting shortcut is a bean that returns new ObjectMapper(). Because Boot's ObjectMapper bean is conditional on there being none, ours replaces it, and with it every default and every property. Dates are written as numeric arrays again, unknown properties suddenly fail requests, the java.time module may be missing, Module beans are no longer registered, and the spring.jackson.* properties stop working without any warning.

Java
@Bean
ObjectMapper objectMapper() { // replaces Boot's mapper entirely
return new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
}
// LocalDateTime field -> error or [2024,5,1,10,30] instead of "2024-05-01T10:30:00"
// unknown field in a request -> 400 (UnrecognizedPropertyException) instead of ignored
// spring.jackson.* properties -> ignored
@Bean
ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) { // if a bean is really needed
return builder.build(); // keeps Boot's defaults and customizers
}
Step throughChoosing how to change a Jackson setting
  1. Is there a spring.jackson property for it?
    YesUse the propertyNoWrite a customizer
  2. Is it a serializer or type support?
    YesRegister a Module beanNoCustomizer changes the builder
  3. Need a second, different mapper?
    YesBuild it from the builder, use a qualifierNoDo not define an ObjectMapper bean

3 steps in order. Play them, or step through them one at a time.

Notice the second version. If we must own the bean, for example to mark a second mapper as a different qualifier, building it from Boot's builder keeps everything Boot configured. In most applications, though, a property or a customizer is enough, and no ObjectMapper bean is needed at all.

6Follow-up questions

Does a Module bean need anything else to be registered?

No. Boot collects all beans of type Module (in Jackson 3, JacksonModule) and adds them to the builder, so declaring the bean is enough. In Boot 3, a class annotated with @JsonComponent that contains serializers is also registered automatically; Boot 4 has an equivalent for Jackson 3, so check its name for your version.

How do I check what the mapper really uses at runtime?

We can inject the ObjectMapper in a test and assert on its features, for example mapper.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS), or simply serialize a sample object and compare the JSON. A @JsonTest slice test starts only the Jackson configuration, which makes this fast.

Can different endpoints use different naming strategies?

Not easily with one mapper, and usually it is a sign of two APIs living in one service. If we really need it, we put @JsonNaming on the specific DTO classes, which overrides the global strategy for those types only.

7Conclusion

In this answer, we saw that Spring Boot builds its ObjectMapper from a Jackson2ObjectMapperBuilder, applies its defaults and the spring.jackson.* properties through a standard customizer, registers well-known modules and every Module bean, and publishes the mapper only if we have not defined our own. We changed the naming strategy with spring.jackson.property-naming-strategy=SNAKE_CASE and with a Jackson2ObjectMapperBuilderCustomizer, and we saw that a plain new ObjectMapper() bean silently throws all of this away. In Boot 4 the same design uses Jackson 3's JsonMapper builder and JsonMapperBuilderCustomizer.

What to say in the interviewAbout 80 seconds aloud

Open with

Spring Boot's JacksonAutoConfiguration doesn't create the ObjectMapper directly. It creates a Jackson2ObjectMapperBuilder, runs customizers on it, and builds the mapper from it. Boot's own customizer applies the spring.jackson properties and Boot's defaults, like writing dates as ISO strings instead of timestamps and not failing on unknown properties.

Then, if they want more

The builder also registers well-known modules from the classpath, like java.time support, and every Module bean in the context. The resulting ObjectMapper is used by the MVC message converters, RestClient and so on. To change something like the naming strategy, the easiest way is a property: spring.jackson.property-naming-strategy=SNAKE_CASE.

If there is no property for what I need, I declare a Jackson2ObjectMapperBuilderCustomizer bean, which adds my change on top of Boot's configuration. For custom serializers I register a Module bean.

What I avoid is declaring my own ObjectMapper bean with new ObjectMapper(), because Boot's mapper is conditional on missing bean, so mine replaces it and I lose all the defaults, the modules and the properties, and suddenly dates come out as arrays. If I really need my own bean, I build it from the injected builder.

In Spring Boot 4 this is Jackson 3, where the mapper is a JsonMapper and the customizer is JsonMapperBuilderCustomizer, but the idea is the same.

About this answer

Last updated
12 November 2026
Versions it names
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 documentation below. 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 "How does Spring Boot configure Jackson's ObjectMapper, and how do you change a setting...": https://scrivio-interview-library.netlify.app/spring-boot/json-serialization/4db58755d5/