Scrivio Interview library
DebuggingFoundations6 min read · updated 12 November 2026

A LocalDateTime field is returned as an array like [2024,5,1,10,30] in one service and as a string in another. Why?

Jackson's java.time module writes dates as numbers or arrays when SerializationFeature.WRITE_DATES_AS_TIMESTAMPS is enabled, which is Jackson 2's own default, so a LocalDateTime becomes [2024,5,1,10,30]. Spring Boot's ObjectMapper disables that feature, so it writes the ISO string "2024-05-01T10:30:00". The service returning arrays is almost certainly not using Boot's mapper: it has defined its own ObjectMapper bean or creates one in code, with the java.time module registered but without Boot's defaults.

Why this question is asked

This is one of the most common JSON surprises in Spring teams, and it usually appears when two services that should behave the same are compared side by side. The field type is the same, the Spring Boot version is the same, yet one response has a readable date and the other has an array of numbers that the client cannot parse. Interviewers ask it because the answer shows whether we know where Jackson's defaults come from and how easily Boot's configuration is replaced. In this answer, we will recap how Jackson handles java.time, reproduce both outputs, find which mapper each service really uses, and fix the odd one out.

1A Quick Recap: Jackson and java.time

Jackson 2's core does not know the java.time types such as LocalDate, LocalDateTime and Instant, because they arrived in Java 8 after Jackson's core design. Support comes from a separate module, jackson-datatype-jsr310, whose JavaTimeModule must be registered with the mapper. Since Jackson 2.12, trying to serialize a LocalDateTime without the module fails with an InvalidDefinitionException saying Java 8 date/time types are not supported by default and naming the module to add.

Once the module is registered, one feature decides the shape: SerializationFeature.WRITE_DATES_AS_TIMESTAMPS. When it is enabled, the module writes dates in a numeric form, an array of fields for local types and a number for Instant. When it is disabled, it writes ISO-8601 strings. In Jackson 2 this feature is enabled by default, a choice that dates back to java.util.Date being written as epoch milliseconds.

2Reproducing Both Outputs

The same object, two mappers, two results.

Java
record Meeting(String title, LocalDateTime start) {}
Meeting m = new Meeting("Review", LocalDateTime.of(2024, 5, 1, 10, 30));
ObjectMapper plain = new ObjectMapper().registerModule(new JavaTimeModule());
plain.writeValueAsString(m);
// {"title":"Review","start":[2024,5,1,10,30]} seconds and nanos are left out when zero
ObjectMapper noModule = new ObjectMapper();
noModule.writeValueAsString(m);
// InvalidDefinitionException: Java 8 date/time type `java.time.LocalDateTime` not supported by default
ObjectMapper boot = Jackson2ObjectMapperBuilder.json()
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build(); // what Boot does
boot.writeValueAsString(m);
// {"title":"Review","start":"2024-05-01T10:30:00"}

Notice the array: year, month, day, hour, minute, with seconds and nanoseconds added only when they are not zero. So the same field can produce arrays of different lengths depending on the value, which is one more reason clients struggle with it. Notice also that Spring's Jackson2ObjectMapperBuilder registers the java.time module automatically when it is on the classpath, but it is Boot's auto-configuration that disables WRITE_DATES_AS_TIMESTAMPS. A mapper from the plain builder without Boot's settings still writes arrays.

3Finding Which Mapper the First Service Uses

Spring Boot creates its ObjectMapper only if the application has not defined one. So the first thing to look for in the service with arrays is a bean method returning ObjectMapper, often in a configuration class written years ago to register a module or set one option. That bean replaces Boot's, and with it Boot's date setting. Other causes are a property spring.jackson.serialization.write-dates-as-timestamps=true, a message converter built by hand with new MappingJackson2HttpMessageConverter(new ObjectMapper()), or a RestTemplate or Kafka serializer that was given its own mapper.

Java
// Found in the first service's configuration
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule()); // dates work, but as arrays
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper; // Boot's ObjectMapper is now skipped
}
// Quick check from a test or an actuator endpoint
mapper.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // true here, false with Boot's mapper
Step throughWhy does this service write dates as arrays?
  1. Is there an ObjectMapper @Bean in the app?
    YesIt replaces Boot's mapper: likely causeNoCheck properties
  2. write-dates-as-timestamps=true set?
    YesThe property enables arraysNoCheck other mappers
  3. Converter, client or serializer with its own mapper?
    YesThat path ignores Boot's settingsNoCheck @JsonFormat on the field
  4. Fix the sourceuse Boot's mapper or its builder

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

Notice that the custom bean was probably added for an unrelated reason, here NON_NULL inclusion. Its author did not intend to change dates; they simply did not know that a new ObjectMapper starts from Jackson's defaults, not Boot's.

4Fixing the Service

The best fix is to delete the custom bean and express its intent the Boot way: a property for the inclusion setting, which keeps Boot's date handling and everything else. If the bean must stay, it should be built from the builder Boot provides, so it inherits Boot's defaults and customizers.

Java
# Option 1: remove the bean, use properties
spring.jackson.default-property-inclusion=non_null
// Option 2: keep a bean, but build it from Boot's builder
@Bean
ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
return builder.serializationInclusion(JsonInclude.Include.NON_NULL).build();
}
// GET /meetings/1 -> {"title":"Review","start":"2024-05-01T10:30:00"}

Notice that this changes the API: clients of the first service were receiving arrays and may have written code to parse them. Before the fix goes out, we tell those clients, and if needed we keep arrays for an existing endpoint with @JsonFormat(shape = JsonFormat.Shape.ARRAY) on the field for a transition period. In Spring Boot 4 with Jackson 3, java.time support is built into Jackson and the date defaults were revisited, so check the Boot 4 release notes for how such a custom mapper behaves after the upgrade.

5Follow-up questions

Why does Jackson 2 default to timestamps at all?

For compatibility with its early behaviour, when java.util.Date was written as epoch milliseconds. Changing a default in a minor version would have broken many applications, so Jackson kept it and frameworks such as Spring Boot changed it in their own configuration.

Can I fix only one field without touching the mapper?

Yes, @JsonFormat(shape = JsonFormat.Shape.STRING) on the field makes it a string, and a pattern can be added. But fixing one field hides the real problem, which is that the service does not use Boot's configuration, and other differences, such as unknown property handling, are probably hiding too.

What is written for Instant when timestamps are enabled?

A number of seconds since the epoch with a fractional part for nanoseconds, such as 1714559400.000000000, unless WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS is disabled, in which case it is milliseconds. With timestamps disabled, it is an ISO string ending in Z.

6Conclusion

In this answer, we saw that the array comes from Jackson's java.time module writing local types in numeric form when WRITE_DATES_AS_TIMESTAMPS is enabled, which is Jackson 2's own default. Spring Boot disables that feature, so Boot's mapper writes ISO strings. The service with arrays has replaced Boot's mapper, usually with an ObjectMapper bean created with new ObjectMapper(), or uses a separate mapper somewhere. The fix is to remove that bean in favour of properties or build it from Boot's builder, and to tell clients before the format changes.

What to say in the interviewAbout 70 seconds aloud

Open with

The array is what Jackson's java.time module writes when SerializationFeature.WRITE_DATES_AS_TIMESTAMPS is enabled: year, month, day, hour, minute, and seconds only if they are not zero. That feature is enabled by default in plain Jackson 2.

Then, if they want more

Spring Boot's auto-configured ObjectMapper disables it, so with Boot's mapper the same LocalDateTime comes out as the ISO string 2024-05-01T10:30:00. Boot also makes sure the java.time module is registered; without it, Jackson 2.12 and later just throws an InvalidDefinitionException for LocalDateTime. So the service with arrays is almost certainly not using Boot's mapper.

The usual cause is an ObjectMapper @Bean somewhere, created with new ObjectMapper() plus registerModule(new JavaTimeModule()), maybe just to set NON_NULL. Because Boot's mapper is conditional on no other ObjectMapper bean, that bean silently replaces it and starts from Jackson's defaults. Other causes are the property write-dates-as-timestamps set to true, or a converter or client built with its own mapper.

I'd confirm by checking isEnabled on the injected mapper, then remove the bean and use spring.jackson properties instead, or build the bean from Boot's Jackson2ObjectMapperBuilder. Since clients of that service may parse arrays today, I'd announce the change first.

About this answer

Last updated
12 November 2026
Versions it names
Java 8, 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 "A LocalDateTime field is returned as an array like [2024,5,1,10,30] in one service and...": https://scrivio-interview-library.netlify.app/spring-boot/json-serialization/a2857d6699/