If you are moving to Jackson 3 and went looking for JavaTimeModule, here is the short answer: delete it. In Jackson 3, java.time support is part of jackson-databind. A plain JsonMapper writes LocalDate, LocalDateTime, Instant, OffsetDateTime and ZonedDateTime as ISO-8601 strings with no dependency, registration or flag.
The longer answer matters more. The default output changed, a few types changed shape in ways no compiler will tell you about, and Spring Boot’s property names moved. This guide starts at the first date you serialise and works up to time zones, @JsonFormat traps, Boot 4 configuration and reading data that Jackson 2 wrote. Every output block below was captured from a real run.
Verified versions. Jackson 3.3.0 and 2.23.0 (withjackson-datatype-jsr3102.23.0) on Temurin JDK 25.0.5.1 and Maven 3.9.11. The Spring section uses Spring Boot 4.2.0, which manages Jackson 3.1.8; where 3.1.8 behaves differently from 3.3.0, the text says so. Jackson 3 movedjava.timesupport into databind in the 3.0 line (3.0.0 was released on 3 October 2025).
Runnable code: the java-time module of thejackson3-by-examplerepository. Every console block links to its file in output/. Programs run with-Duser.timezone=UTCunless they change the zone themselves.
Why JavaTimeModule is no longer needed
The java.time classes (LocalDate, Instant and friends) arrived in Java 8, while Jackson 2 still had to run on older Java versions. So Jackson 2 shipped their support in a separate jar, jackson-datatype-jsr310, whose JavaTimeModule you had to register. Jackson 3 needs Java 17, so there is no reason to keep them apart.
Read the picture left to right: on the left, two jars and one line of glue code; on the right, one jar. This is the sample record every program serialises, from Meeting.java:
public record Meeting(LocalDate day,
LocalDateTime wallClock,
Instant createdAt,
OffsetDateTime startsAt,
ZonedDateTime reminderAt) { }And the comparison, from T01NoModuleNeeded.java:
ObjectMapper plain2 = new ObjectMapper();
System.out.println("== Jackson " + plain2.version() + ", plain ObjectMapper");
try {
plain2.writeValueAsString(meeting);
} catch (Exception e) {
System.out.println(Samples.firstLine(e));
}
ObjectMapper module2 = new ObjectMapper().registerModule(new JavaTimeModule());
System.out.println();
System.out.println("== Jackson 2 + JavaTimeModule");
System.out.println(module2.writeValueAsString(meeting));
JsonMapper m3 = JsonMapper.builder().build();
System.out.println();
System.out.println("== Jackson " + m3.version() + ", JsonMapper.builder().build()");
String json = m3.writeValueAsString(meeting);
System.out.println(json);
System.out.println("registered modules : " + m3.registeredModules().size());
System.out.println("read back : " + m3.readValue(json, Meeting.class));== Jackson 2.23.0, plain ObjectMapper
InvalidDefinitionException: Java 8 date/time type `java.time.LocalDate` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (or disable `MapperFeature.REQUIRE_HANDLERS_FOR_JAVA8_TIMES`) (through reference chain: com.ankurm.javatime.Meeting["day"])
== Jackson 2 + JavaTimeModule
{"day":[2026,12,15],"wallClock":[2026,12,15,10,30],"createdAt":1797310800.000000000,"startsAt":1797310800.000000000,"reminderAt":1797310800.000000000}
== Jackson 3.3.0, JsonMapper.builder().build()
{"day":"2026-12-15","wallClock":"2026-12-15T10:30:00","createdAt":"2026-12-15T05:00:00Z","startsAt":"2026-12-15T10:30:00+05:30","reminderAt":"2026-12-15T10:30:00+05:30"}
registered modules : 0
read back : Meeting[day=2026-12-15, wallClock=2026-12-15T10:30, createdAt=2026-12-15T05:00:00Z, startsAt=2026-12-15T05:00Z, reminderAt=2026-12-15T05:00Z]Four things to take from that output. Jackson 2 without the module refuses outright. Jackson 2 with the module still writes arrays and decimal numbers. Jackson 3 writes readable strings with registered modules : 0. And the last line, read back, shows both offsets turned into Z, which the next-but-one section explains.
What if you leave the old registration in place? It does not compile, because the Jackson 2 module is not a Jackson 3 JacksonModule. The same is true of the old home of the timestamp flag. Both sources are in src/broken:
=== OldFlagLocation.java ===
OldFlagLocation.java:7: error: cannot find symbol
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
^
1 error
=== RegisterJackson2Module.java ===
RegisterJackson2Module.java:8: error: incompatible types: JavaTimeModule cannot be converted to JacksonModule
.addModule(new JavaTimeModule())
^
1 errorSo the migration is a deletion. Remove this dependency (shown here in the module’s pom.xml, which keeps it only to run the Jackson 2 side of the comparisons), remove every registerModule(new JavaTimeModule()), and remove the matching imports:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>Going deeper: where the support lives now
The classes sit in tools.jackson.databind.ext.javatime, and a JavaTimeInitializer there is wired in by the mapper itself. The last block of output/01 checks the class names: the Jackson 2 JavaTimeModule is present only because this module deliberately has both majors on the classpath, and there is no tools.jackson.datatype.jsr310.JavaTimeModule at all. The official Jackson 3 migration guide says to remove the dependency and the registrations.
- Jackson 2 to Jackson 3 migration guide: package rename, unchecked exceptions and the other removals
- Jackson 3 vs Jackson 2: the full comparison
- ObjectMapper and JsonMapper guide for how the builder works
Jackson 2 vs Jackson 3: the date output diff table
The most visible change is a single default. WRITE_DATES_AS_TIMESTAMPS was on in Jackson 2 and is off in Jackson 3, and the flag moved from SerializationFeature to tools.jackson.databind.cfg.DateTimeFeature. A second flag, WRITE_DURATIONS_AS_TIMESTAMPS, is off too.
The table below is generated from output/02-OutputDiff.txt, produced by T02OutputDiff.java. Value names in bold changed between the first and third column, in other words between a typical Jackson 2 setup and a default Jackson 3 one. The sample moment is 15 December 2026, 10:30 in India (05:00 UTC).
| Value | Jackson 2.23 + JavaTimeModule | Jackson 2.23 + module, timestamps disabled | Jackson 3.3.0 default | Jackson 3.3.0 builderWithJackson2Defaults() |
|---|---|---|---|---|
| LocalDate | [2026,12,15] | "2026-12-15" | "2026-12-15" | [2026,12,15] |
| LocalTime | [10,30] | "10:30:00" | "10:30:00" | [10,30] |
| LocalDateTime | [2026,12,15,10,30] | "2026-12-15T10:30:00" | "2026-12-15T10:30:00" | [2026,12,15,10,30] |
| LocalDateTime+nanos | [2026,12,15,10,30,0,123456000] | "2026-12-15T10:30:00.123456" | "2026-12-15T10:30:00.123456" | [2026,12,15,10,30,0,123456000] |
| Instant | 1797310800.000000000 | "2026-12-15T05:00:00Z" | "2026-12-15T05:00:00Z" | 1797310800.000000000 |
| OffsetDateTime | 1797310800.000000000 | "2026-12-15T10:30:00+05:30" | "2026-12-15T10:30:00+05:30" | 1797310800.000000000 |
| ZonedDateTime | 1797310800.000000000 | "2026-12-15T10:30:00+05:30" | "2026-12-15T10:30:00+05:30" | 1797310800.000000000 |
| Duration | 5400.000000000 | 5400.000000000 | "PT1H30M" | 5400.000000000 |
| Period | "P1Y2M3D" | "P1Y2M3D" | "P1Y2M3D" | "P1Y2M3D" |
| Year | 2026 | "2026" | 2026 | 2026 |
| YearMonth | [2026,12] | "2026-12" | "2026-12" | [2026,12] |
| MonthDay | "--12-15" | "--12-15" | "--12-15" | "--12-15" |
| Month | "DECEMBER" | "DECEMBER" | 12 | 11 |
| DayOfWeek | "TUESDAY" | "TUESDAY" | "TUESDAY" | "TUESDAY" |
| ZoneId | "Asia/Kolkata" | "Asia/Kolkata" | "Asia/Kolkata" | "Asia/Kolkata" |
| ZoneOffset | "+05:30" | "+05:30" | "+05:30" | "+05:30" |
| java.util.Date | 1797310800000 | "2026-12-15T05:00:00.000+00:00" | "2026-12-15T05:00:00.000Z" | 1797310800000 |
| java.sql.Date | 1797292800000 | "2026-12-15" | "2026-12-15T00:00:00.000Z" | 1797292800000 |
| Map<LocalDate,..> key | {"2026-12-15":1} | {"2026-12-15":1} | {"2026-12-15":1} | {"2026-12-15":1} |
| Map<Date,..> key | {"2026-12-15T05:00:00.000+00:00":1} | {"2026-12-15T05:00:00.000+00:00":1} | {"2026-12-15T05:00:00.000Z":1} | {"2026-12-15T05:00:00.000+00:00":1} |
Disabling timestamps on Jackson 2 was not the same as moving to Jackson 3. Compare the second and third columns: Duration, Year, Month, java.util.Date (+00:00 became Z) and java.sql.Date still differ.
java.sql.Date changed meaning, not just spelling. With timestamps disabled, Jackson 2 wrote"2026-12-15". Jackson 3 writes it like ajava.util.Date. The run behind the table used UTC, so it shows midnight UTC; in a JVM set to Asia/Kolkata the same date serialises as 14 December at 18:30 UTC (see the time zone section). UseLocalDatefor calendar dates.
These are the date-related switches and their defaults, printed by T03FeatureDefaults.java:
DateTimeFeature default with Jackson 2 defaults
ADJUST_DATES_TO_CONTEXT_TIME_ZONE true true
ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS false false
ALWAYS_WRITE_SUBSECOND_DIGITS false false
NORMALIZE_DESERIALIZED_ZONE_ID true true
ONE_BASED_MONTHS true false
READ_DATE_TIMESTAMPS_AS_NANOSECONDS true true
TRUNCATE_TO_MSECS_ON_READ false false
TRUNCATE_TO_MSECS_ON_WRITE false false
USE_TIME_ZONE_FOR_LENIENT_DATE_PARSING false false
WRITE_DATES_AS_TIMESTAMPS false true
WRITE_DATE_KEYS_AS_TIMESTAMPS false false
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS true true
WRITE_DATES_WITH_CONTEXT_TIME_ZONE true true
WRITE_DATES_WITH_ZONE_ID false false
WRITE_DURATIONS_AS_TIMESTAMPS false true
WRITE_UTC_AS_OFFSET false true
default time zone (mapper): UTCThe right-hand column is the escape hatch: JsonMapper.builderWithJackson2Defaults() turns the timestamp flags back on. It is useful for keeping an old contract alive, but read the Month section before trusting it to be byte-compatible. (ALWAYS_WRITE_SUBSECOND_DIGITS is new in 3.3.0 and absent from the 3.1.8 list.)
Going deeper: the individual features and where they came from
Per the official Jackson 3 migration guide, ADJUST_DATES_TO_CONTEXT_TIME_ZONE and READ_DATE_TIMESTAMPS_AS_NANOSECONDS moved from DeserializationFeature, and the WRITE_DATE* and WRITE_DURATIONS_AS_TIMESTAMPS flags moved from SerializationFeature, all into DateTimeFeature, which also replaces the module-specific JavaTimeFeature. The jackson-databind release notes record the move of the module into databind as #5032 and the new ONE_BASED_MONTHS default around #5065–#5067.
- Jackson 3 vs Jackson 2: the full comparison
- java.util.Date and Calendar to java.time migration guide if your code still passes
Datearound
Reading dates back: the offset you sent may not be the offset you get
Before choosing types, fix the mental model. LocalDate and LocalDateTime are calendar and wall-clock readings with no zone. Instant is a point on the timeline. OffsetDateTime is a wall-clock reading plus a fixed offset such as +05:30. ZonedDateTime adds a region such as Asia/Kolkata, which knows about daylight saving rules.
| Type | Default Jackson 3 JSON | Use it for |
|---|---|---|
LocalDate | "2026-12-15" | birthdays, due dates |
LocalDateTime | "2026-12-15T10:30:00" | local schedules where the zone is stored elsewhere or does not matter |
Instant | "2026-12-15T05:00:00Z" | audit stamps, event times |
OffsetDateTime | "2026-12-15T10:30:00+05:30" | API fields where the sender’s local time matters |
ZonedDateTime | "2026-12-15T10:30:00+05:30" (region dropped) | future appointments in a named region, with the zone id switched on |
The diagram shows what is probably the most surprising behaviour for beginners: serialising keeps your offset, but deserialising converts it to the mapper’s zone. T04ReadingOffsets.java reads one string several ways:
input: "2026-12-15T10:30:00+05:30"
== Jackson 2.23.0 + JavaTimeModule, defaults
OffsetDateTime : 2026-12-15T05:00Z
ZonedDateTime : 2026-12-15T05:00Z
Instant : 2026-12-15T05:00:00Z
== Jackson 3 defaults (mapper zone UTC)
OffsetDateTime : 2026-12-15T05:00Z
ZonedDateTime : 2026-12-15T05:00Z
Instant : 2026-12-15T05:00:00Z
== Jackson 3, defaultTimeZone(Asia/Kolkata)
OffsetDateTime : 2026-12-15T10:30+05:30
ZonedDateTime : 2026-12-15T10:30+05:30[Asia/Kolkata]
Instant : 2026-12-15T05:00:00Z
== Jackson 3, ADJUST_DATES_TO_CONTEXT_TIME_ZONE disabled
OffsetDateTime : 2026-12-15T10:30+05:30Jackson 2 did the same thing, so this is not a regression; it is a default many applications never noticed. If your code reads getOffset() or getHour() from an incoming value, disable the adjustment:
JsonMapper keep = JsonMapper.builder()
.disable(DateTimeFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE).build();The region id is a second, separate loss. Default output of a ZonedDateTime contains only the offset, so what you read back is no longer in Asia/Kolkata. WRITE_DATES_WITH_ZONE_ID keeps it, in a bracket form that other consumers may not parse:
== A region id survives only if you ask for it
original : 2026-12-15T10:30+05:30[Asia/Kolkata]
written by default : "2026-12-15T10:30:00+05:30"
read back : 2026-12-15T10:30+05:30
WRITE_DATES_WITH_ZONE_ID : "2026-12-15T10:30:00+05:30[Asia/Kolkata]"
read back : 2026-12-15T10:30+05:30[Asia/Kolkata]Going deeper: Instant, and which type to persist
Instant is unaffected by all of the above: it has no offset to lose, and it is written with Z in every default-format run here. For future events (a meeting at 09:00 in London next summer) an instant computed today can become wrong if the zone rules change, so store the local date-time plus the zone id. That is a modelling decision rather than a Jackson one.
Time zones: which settings actually move the output
There are two zones people confuse. The JVM default zone comes from the operating system or -Duser.timezone. The mapper zone is set with defaultTimeZone(..) and is UTC unless you set it; Jackson 3 does not borrow the JVM’s.
The grid says that modern types carry their own information, so neither zone rewrites their default output. Only the legacy types and pattern-formatted offset types move. T05TimeZones.java sets each zone and prints the same values:
== JVM zone Asia/Kolkata, mapper defaults
{
"localDateTime" : "2026-12-15T10:30:00",
"instant" : "2026-12-15T05:00:00Z",
"offset" : "2026-12-15T10:30:00+05:30",
"zoned" : "2026-12-15T10:30:00+05:30",
"utilDate" : "2026-12-15T05:00:00.000Z",
"sqlDate" : "2026-12-14T18:30:00.000Z"
}That sqlDate line is 15 December turned into 14 December. java.sql.Date.valueOf means midnight in the JVM zone, and Jackson 3 renders that instant in UTC. With a mapper zone of Asia/Kolkata the java.util.Date output changes spelling while every java.time line stays put:
== JVM zone UTC, defaultTimeZone(Asia/Kolkata)
{
"localDateTime" : "2026-12-15T10:30:00",
"instant" : "2026-12-15T05:00:00Z",
"offset" : "2026-12-15T10:30:00+05:30",
"zoned" : "2026-12-15T10:30:00+05:30",
"utilDate" : "2026-12-15T10:30:00.000+05:30",
"sqlDate" : "2026-12-15T05:30:00.000+05:30"
}The exception to “modern types stay put” is a custom pattern. Once you format an offset type with @JsonFormat(pattern = ...) and have set a mapper zone explicitly, WRITE_DATES_WITH_CONTEXT_TIME_ZONE (on by default) converts the value to that zone:
== @JsonFormat(pattern) on offset types, values are at +05:30
mapper zone not set : {"offset":"2026-12-15 10:30 +05:30","zoned":"2026-12-15 10:30 +05:30"}
not set, JVM zone New York : {"offset":"2026-12-15 10:30 +05:30","zoned":"2026-12-15 10:30 +05:30"}
defaultTimeZone(Europe/London) : {"offset":"2026-12-15 05:00 Z","zoned":"2026-12-15 05:00 Z"}
London, CONTEXT_TIME_ZONE disabled: {"offset":"2026-12-15 10:30 +05:30","zoned":"2026-12-15 10:30 +05:30"}Going deeper: zone settings worth knowing
Setting the mapper zone also changes what incoming offset values are converted to, as the previous section showed. Prefer leaving the mapper in UTC, keeping the offsets you receive, and converting to a user’s zone at the edge where you know which user it is.
- All zone runs in full
- official Jackson 3 migration guide (date format and time zone defaults)
@JsonFormat patterns on java.time fields
@JsonFormat is still com.fasterxml.jackson.annotation.JsonFormat, even on Jackson 3, because the annotations jar kept its old package. Use it when one field needs a non-ISO format. T06JsonFormat.java shows the useful options:
public record Invoice(
@JsonFormat(pattern = "dd/MM/yyyy") LocalDate issued,
@JsonFormat(pattern = "dd-MM-yyyy HH:mm") LocalDateTime dueAt,
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Kolkata") Instant paidAt,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mmXXX",
without = JsonFormat.Feature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE) OffsetDateTime signedAt,
@JsonFormat(pattern = "d MMMM yyyy", locale = "fr_FR") LocalDate printed,
@JsonFormat(shape = JsonFormat.Shape.NUMBER) Instant epochSeconds,
@JsonFormat(shape = JsonFormat.Shape.NUMBER,
without = JsonFormat.Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS) Instant writeOnlyMillis,
@JsonFormat(shape = JsonFormat.Shape.NUMBER, without = {
JsonFormat.Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS,
JsonFormat.Feature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS}) Instant epochMillis,
@JsonFormat(shape = JsonFormat.Shape.ARRAY) LocalDate asArray,
Month monthDefault,
@JsonFormat(shape = JsonFormat.Shape.STRING) Month monthName) { }{
"issued" : "15/12/2026",
"dueAt" : "15-12-2026 10:30",
"paidAt" : "2026-12-15 10:30:00",
"signedAt" : "2026-12-15T10:30+05:30",
"printed" : "15 décembre 2026",
"epochSeconds" : 1797310800.000000000,
"writeOnlyMillis" : 1797310800000,
"epochMillis" : 1797310800000,
"asArray" : [ 2026, 12, 15 ],
"monthDefault" : 12,
"monthName" : "DECEMBER"
}Note what each attribute buys. pattern sets the text. timezone gives an Instant the calendar fields a pattern needs. without = ADJUST_DATES_TO_CONTEXT_TIME_ZONE keeps the offset on one field only. locale controls month names. shape = NUMBER or ARRAY asks for the numeric forms. Now read the same JSON back:
issued : 2026-12-15
dueAt : 2026-12-15T10:30
paidAt : 2026-12-15T05:00:00Z
signedAt : 2026-12-15T10:30+05:30
printed : 2026-12-15
epochSeconds : 2026-12-15T05:00:00Z
writeOnlyMillis : +58924-07-06T08:00:00Z
epochMillis : 2026-12-15T05:00:00Z
asArray : 2026-12-15
monthDefault : DECEMBER
monthName : DECEMBERA write-only feature does not round-trip.writeOnlyMillisdisables nanosecond timestamps for writing only, so the field is written as milliseconds and read as seconds: the year 58924. Disable bothWRITE_DATE_TIMESTAMPS_AS_NANOSECONDSandREAD_DATE_TIMESTAMPS_AS_NANOSECONDS, asepochMillisdoes.
Going deeper: Month shape STRING needs Jackson 3.3.0
The monthName line above is from 3.3.0. On 3.1.8 and 3.2.4 the same annotation still wrote a number (see output/12). The jackson-databind release notes list the fix in 3.3.0 as #6233. The Month section below gives a workaround that works on the older lines.
- Jackson annotations guide for the rest of
@JsonFormatand its neighbours - DateTimeFormatter pattern letters (Java 25 API)
Four patterns that run and give the wrong answer
Patterns are plain DateTimeFormatter patterns, so they inherit its sharp edges. T07FormatTraps.java declares one record per mistake:
record Default(@JsonFormat(pattern = "yyyy-MM-dd") LocalDate day) { }
record StrictY(@JsonFormat(pattern = "yyyy-MM-dd", lenient = OptBoolean.FALSE) LocalDate day) { }
record StrictU(@JsonFormat(pattern = "uuuu-MM-dd", lenient = OptBoolean.FALSE) LocalDate day) { }
record WeekYear(@JsonFormat(pattern = "YYYY-MM-dd") LocalDate day) { }
record CalendarYear(@JsonFormat(pattern = "yyyy-MM-dd") LocalDate day) { }
record FakeZ(@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") LocalDateTime at) { }
record NoZone(@JsonFormat(pattern = "yyyy-MM-dd HH:mm") Instant at) { }
record ZonedNoZone(@JsonFormat(pattern = "yyyy-MM-dd HH:mm") ZonedDateTime at) { }Adding a pattern can make parsing more forgiving. Without a pattern, 30 February is rejected. With yyyy-MM-dd and no lenient setting it is silently turned into 28 February. The obvious fix, lenient = OptBoolean.FALSE, then rejects every date if the pattern says yyyy; strict resolution needs uuuu:
pattern : Default[day=2026-02-28]
lenient=FALSE, yyyy ok : InvalidFormatException: Cannot deserialize value of type `java.time.LocalDate` from String "2026-02-28": Failed to deserialize `java.time.LocalDate` (with format 'Value(YearOfEra,4,19,EXCEEDS_PAD)'-'Value(MonthOfYear,2)'-'Value(DayOfMonth,2)'): (java.time.format.DateTimeParseException) Text '2026-02-28' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {MonthOfYear=2, DayOfMonth=28, YearOfEra=2026},ISO of type java.time.format.Parsed
lenient=FALSE, uuuu : InvalidFormatException: Cannot deserialize value of type `java.time.LocalDate` from String "2026-02-30": Failed to deserialize `java.time.LocalDate` (with format 'Value(Year,4,19,EXCEEDS_PAD)'-'Value(MonthOfYear,2)'-'Value(DayOfMonth,2)'): (java.time.format.DateTimeParseException) Text '2026-02-30' could not be parsed: Invalid date 'FEBRUARY 30'
lenient=FALSE, uuuu ok : StrictU[day=2026-02-28]YYYY is not the year. It is the week-based year, which depends on the locale and differs near New Year. A quoted 'Z' is just a letter: it stamps “UTC” onto a value that never was converted. Here 10:30 India time is announced as 10:30 UTC:
== YYYY is the week-based year, yyyy is the calendar year
value 2026-12-29, YYYY : {"day":"2027-12-29"}
value 2026-12-29, yyyy : {"day":"2026-12-29"}== A quoted 'Z' is just a letter
10:30 India wall clock : {"at":"2026-12-15T10:30:00Z"}An Instant pattern without a zone fails at runtime, not at compile time: Instant has no year or hour until you choose a zone.
Instant, no timezone : DatabindException: Unsupported field: YearOfEra
ZonedDateTime : {"at":"2026-12-15 10:30"}Finally, know what an unannotated field will accept. LocalDate accepted a date-time string and simply kept the date part, even for a Z value that is already the next day in India. LocalDateTime accepted a trailing Z but rejected +05:30:
LocalDateTime <- ...Z : 2026-12-15T05:00
LocalDate <- date-time : 2026-12-15
LocalDate <- ...Z : 2026-12-15
LocalDate <- "" : nullGoing deeper: the full error text
The exception lines are long because they print the whole formatter; the useful part is at the end, for example Invalid date 'FEBRUARY 30' or Unsupported field: YearOfEra. Every case is in output/07. Date parsing errors arrive as Jackson exceptions, which in Jackson 3 are unchecked; see JsonProcessingException vs JacksonException in Jackson 3.
- DateTimeFormatter pattern letters (Java 25 API), especially
y,uandY - Jackson 2 to Jackson 3 migration guide on the unchecked
JacksonException
Bare numbers: seconds or milliseconds?
Many clients, JavaScript among them, send epoch milliseconds. Jackson’s java.time types read a whole number as epoch seconds by default, while java.util.Date reads it as milliseconds. T08EpochNumbers.java:
expected instant : 2026-12-15T05:00:00Z
defaults, Instant <- seconds : 2026-12-15T05:00:00Z
defaults, Instant <- milliseconds : +58924-07-06T08:00:00Z
defaults, Instant <- 1797310800.5 : 2026-12-15T05:00:00.500Z
NANOSECONDS off, Instant <- milliseconds: 2026-12-15T05:00:00Z
NANOSECONDS off, Instant <- seconds : 1970-01-21T19:15:10.800Z
defaults, java.util.Date <- milliseconds: 2026-12-15T05:00:00Z
defaults, java.util.Date <- seconds : 1970-01-21T19:15:10.800Z
defaults, Instant <- "1797310800" : 2026-12-15T05:00:00ZNothing throws. A milliseconds value lands about 57,000 years in the future, and seconds fed to a Date land in January 1970. If your producers send milliseconds to Instant fields, disable READ_DATE_TIMESTAMPS_AS_NANOSECONDS for that mapper, or better, agree on ISO strings. A validation rule such as “date must be within ten years of now” catches both mistakes.
Going deeper: writing numbers
When you enable WRITE_DATES_AS_TIMESTAMPS, Instant is written as seconds with nine decimals (see the diff table). Disabling WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS gives integer milliseconds; disable the matching read feature with it.
- Epoch transcript
- jackson-databind release notes (3.1.6 added a size limit on numbers fed to the
Instantdeserializer)
Set a date format once for the whole application
Annotating hundreds of fields is not maintenance. There are three mapper-wide options, and they do not reach the same types. T09GlobalFormats.java:
JsonMapper dateFormat = JsonMapper.builder()
.defaultDateFormat(new SimpleDateFormat("dd/MM/yyyy HH:mm"))
.build();
show("defaultDateFormat(SimpleDateFormat)", dateFormat, row);
JsonMapper perType = JsonMapper.builder()
.withConfigOverride(LocalDate.class,
o -> o.setFormat(JsonFormat.Value.forPattern("dd/MM/yyyy")))
.withConfigOverride(LocalDateTime.class,
o -> o.setFormat(JsonFormat.Value.forPattern("dd/MM/yyyy HH:mm")))
.build();
show("withConfigOverride per type", perType, row);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm");
SimpleModule module = new SimpleModule()
.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter))
.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter));
show("SimpleModule with a DateTimeFormatter",
JsonMapper.builder().addModule(module).build(), row);== defaultDateFormat(SimpleDateFormat)
{"day":"2026-12-15","at":"2026-12-15T10:30:00","legacy":"15/12/2026 05:00"}
read back: 2026-12-15T10:30
== withConfigOverride per type
{"day":"15/12/2026","at":"15/12/2026 10:30","legacy":"2026-12-15T05:00:00.000Z"}
read back: 2026-12-15T10:30
== SimpleModule with a DateTimeFormatter
{"day":"2026-12-15","at":"15.12.2026 10.30","legacy":"2026-12-15T05:00:00.000Z"}
read back: 2026-12-15T10:30
== an annotation beats the global override
{"day":"20261215","at":"15/12/2026 10:30","legacy":"2026-12-15T05:00:00.000Z"}| Mechanism | Reaches | Does not reach |
|---|---|---|
defaultDateFormat(SimpleDateFormat) | java.util.Date | LocalDate, LocalDateTime |
withConfigOverride(type, ..) | the one type you name, reading and writing | other types |
SimpleModule with a formatter serializer and deserializer | the one type you register | other types; register both directions |
A field annotation wins over a global override, as the last block of the output shows. For most projects withConfigOverride is the least code.
Going deeper: when you need real code
If a format depends on more than the type (accepting two input formats, say), write a deserializer. The Jackson 3 base classes were renamed to ValueSerializer and ValueDeserializer.
The Month trap: a number that can be off by one
java.time.Month is an enum, and Jackson 2 wrote it by name. Jackson 3 gives it a dedicated serializer that writes a number, 1-based by default (ONE_BASED_MONTHS). A Jackson 2 consumer reads numbers 0-based.
The figure shows the most dangerous failure in this migration, because it is silent. T11MonthTrap.java sends November across every combination, here on Jackson 3.3.0:
value sent : NOVEMBER
Jackson 2 writes : {"month":"NOVEMBER"}
Jackson 3 defaults write : {"month":11}
Jackson 3 reads it : NOVEMBER
Jackson 2 reads it : DECEMBER
Jackson 2 + ONE_BASED_MONTHS reads : NOVEMBER
Jackson 3, ONE_BASED_MONTHS off : {"month":10}
Jackson 3 defaults read it : OCTOBER
Jackson 2 reads it : NOVEMBER
Jackson 3, Month override STRING : {"month":"NOVEMBER"}
Jackson 3 reads it : NOVEMBER
Jackson 2 reads it : NOVEMBER
Jackson 3, @JsonFormat(shape=STRING) : {"month":"NOVEMBER"}
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}Turning ONE_BASED_MONTHS off only moves the problem to the other side. Writing the name is the safe choice, and how you do that depends on your Jackson version:
/** Works on every 3.x line tried here, including the one Spring Boot 4.2.0 manages. */
static final class MonthNameSerializer extends StdSerializer<Month> {
MonthNameSerializer() {
super(Month.class);
}
@Override
public void serialize(Month value, JsonGenerator gen, SerializationContext context) {
gen.writeString(value.name());
}
}######## Jackson 3.1.8
value sent : NOVEMBER
Jackson 2 writes : {"month":"NOVEMBER"}
Jackson 3 defaults write : {"month":11}
Jackson 3 reads it : NOVEMBER
Jackson 2 reads it : DECEMBER
Jackson 2 + ONE_BASED_MONTHS reads : NOVEMBER
Jackson 3, ONE_BASED_MONTHS off : {"month":10}
Jackson 3 defaults read it : OCTOBER
Jackson 2 reads it : NOVEMBER
Jackson 3, Month override STRING : {"month":11}
Jackson 3 reads it : NOVEMBER
Jackson 2 reads it : DECEMBER
Jackson 3, @JsonFormat(shape=STRING) : {"month":11}
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}On the Jackson that Spring Boot 4.2.0 manages, a STRING shape for Month did nothing in my runs. On 3.1.8 both the config override and the annotation still wrote11. Register a serializer as above, or override thejackson-bom.versionproperty to a 3.3.x release and re-test (I did not run Boot with that override).
Going deeper: the same output on 3.2.4 and 3.3.0
output/12 holds all three runs, produced by run-versions.sh. The override and the annotation both work only in the 3.3.0 run. The default (a number) is the same on all of them. DayOfWeek is still written by name.
- jackson-databind release notes: #5078 added the dedicated
MonthSerializerin 3.0.0-rc4, #6233 is the STRING shape fix
Spring Boot 4: spring.jackson.* properties for dates
Spring Boot 4 builds a Jackson 3 JsonMapper for you. Dates in JSON are configured under spring.jackson; dates in query strings are a different system.
Keep the two paths in mind while reading the results. The demo is a small web app: EventController.java exposes a response, a request body and a query parameter, and BootDemo.java restarts it once per configuration and calls it over HTTP.
@GetMapping("/event")
Event event() {
LocalDateTime wall = LocalDateTime.of(2026, 12, 15, 10, 30);
OffsetDateTime start = wall.atOffset(ZoneOffset.ofHoursMinutes(5, 30));
return new Event(wall.toLocalDate(), wall, start.toInstant(), start,
Duration.ofMinutes(90), Month.NOVEMBER, Date.from(start.toInstant()));
}
/** Shows what the controller actually receives after Jackson has read the body. */
@PostMapping("/booking")
Map<String, String> booking(@RequestBody Booking booking) {
return Map.of("received", booking.startsAt().toString());
}
/** A query parameter is converted by Spring MVC, not by Jackson. */
@GetMapping("/search")
Map<String, String> search(@RequestParam LocalDate day) {
return Map.of("parsed", day.toString());| Property | Observed effect on Boot 4.2.0 |
|---|---|
| (none) | ISO strings; Month is 11; incoming +05:30 arrives as 05:00Z |
spring.jackson.datatype.datetime.write-dates-as-timestamps=true | arrays and numbers again; Duration stays PT1H30M (it has its own flag) |
spring.jackson.datatype.datetime.adjust-dates-to-context-time-zone=false | controller receives 10:30+05:30 |
spring.jackson.time-zone=Asia/Kolkata | changes java.util.Date output and what incoming offsets are converted to; java.time output unchanged |
spring.jackson.date-format=dd/MM/yyyy HH:mm | only the java.util.Date field changed |
spring.jackson.use-jackson2-defaults=true | dates stay ISO strings; Date ends in +00:00; November is written as 10 |
spring.mvc.format.date=dd/MM/yyyy | query parameter parsed; JSON unchanged |
Spring Boot 4.2.0, Jackson 3.1.8
==== no spring.jackson.* properties
GET /event -> 200 {"day":"2026-12-15","wallClock":"2026-12-15T10:30:00","createdAt":"2026-12-15T05:00:00Z","startsAt":"2026-12-15T10:30:00+05:30","length":"PT1H30M","month":11,"legacy":"2026-12-15T05:00:00.000Z"}
POST /booking -> 200 {"received":"2026-12-15T05:00Z"}
GET /search?day=2026-12-15 -> 200 {"parsed":"2026-12-15"}
GET /search?day=15/12/2026 -> 400 (Bad Request)==== date-format
spring.jackson.date-format=dd/MM/yyyy HH:mm
GET /event -> 200 {"day":"2026-12-15","wallClock":"2026-12-15T10:30:00","createdAt":"2026-12-15T05:00:00Z","startsAt":"2026-12-15T10:30:00+05:30","length":"PT1H30M","month":11,"legacy":"15/12/2026 05:00"}
POST /booking -> 200 {"received":"2026-12-15T05:00Z"}
GET /search?day=2026-12-15 -> 200 {"parsed":"2026-12-15"}
GET /search?day=15/12/2026 -> 400 (Bad Request)==== time-zone
spring.jackson.time-zone=Asia/Kolkata
GET /event -> 200 {"day":"2026-12-15","wallClock":"2026-12-15T10:30:00","createdAt":"2026-12-15T05:00:00Z","startsAt":"2026-12-15T10:30:00+05:30","length":"PT1H30M","month":11,"legacy":"2026-12-15T10:30:00.000+05:30"}
POST /booking -> 200 {"received":"2026-12-15T10:30+05:30"}
GET /search?day=2026-12-15 -> 200 {"parsed":"2026-12-15"}
GET /search?day=15/12/2026 -> 400 (Bad Request)==== use-jackson2-defaults
spring.jackson.use-jackson2-defaults=true
GET /event -> 200 {"day":"2026-12-15","wallClock":"2026-12-15T10:30:00","createdAt":"2026-12-15T05:00:00Z","startsAt":"2026-12-15T10:30:00+05:30","length":"PT1H30M","month":10,"legacy":"2026-12-15T05:00:00.000+00:00"}
POST /booking -> 200 {"received":"2026-12-15T05:00Z"}==== spring.mvc.format.date
spring.mvc.format.date=dd/MM/yyyy
GET /event -> 200 {"day":"2026-12-15","wallClock":"2026-12-15T10:30:00","createdAt":"2026-12-15T05:00:00Z","startsAt":"2026-12-15T10:30:00+05:30","length":"PT1H30M","month":11,"legacy":"2026-12-15T05:00:00.000Z"}
POST /booking -> 200 {"received":"2026-12-15T05:00Z"}
GET /search?day=2026-12-15 -> 200 {"parsed":"2026-12-15"}
GET /search?day=15/12/2026 -> 200 {"parsed":"2026-12-15"}use-jackson2-defaultsis notbuilderWithJackson2Defaults(). The plain Jackson builder goes back to numeric timestamps. Boot’s auto-configuration applies the Jackson 2 defaults and then disables the date and duration timestamp flags again (visible in its bytecode), so dates stay as strings. It does not restore month names.
If you are upgrading from Boot 3, search your configuration for spring.jackson.serialization.write-dates-as-timestamps. The flag is no longer a SerializationFeature, and the application does not start:
==== Boot 3 property name left in place
spring.jackson.serialization.write-dates-as-timestamps=false
startup FAILED: UnsatisfiedDependencyException
root cause : IllegalArgumentException: No enum constant tools.jackson.databind.SerializationFeature.write-dates-as-timestampsA reasonable starting file for a new API, run as the recommended profile:
# A starting point for a new Spring Boot 4 API. Active with the "recommended" profile.
spring:
jackson:
datatype:
datetime:
# Hand controllers the offset the client sent instead of converting it to the mapper zone.
adjust-dates-to-context-time-zone: false
mvc:
format:
# Query and path parameters are not read by Jackson; state their format separately.
date: iso
date-time: iso==== profile recommended (application-recommended.yml)
spring.profiles.active=recommended
GET /event -> 200 {"day":"2026-12-15","wallClock":"2026-12-15T10:30:00","createdAt":"2026-12-15T05:00:00Z","startsAt":"2026-12-15T10:30:00+05:30","length":"PT1H30M","month":11,"legacy":"2026-12-15T05:00:00.000Z"}
POST /booking -> 200 {"received":"2026-12-15T10:30+05:30"}
GET /search?day=2026-12-15 -> 200 {"parsed":"2026-12-15"}
GET /search?day=15/12/2026 -> 400 (Bad Request)For rules that properties cannot express, such as an Indian dd/MM/yyyy for every LocalDate or month names, add a JsonMapperBuilderCustomizer bean from IndianDatesCustomizer.java:
@Bean
JsonMapperBuilderCustomizer indianDates() {
// Month by name, with a serializer because the Jackson that Boot 4.2.0 manages
// ignores a STRING shape override for Month.
SimpleModule months = new SimpleModule().addSerializer(Month.class, new StdSerializer<Month>(Month.class) {
@Override
public void serialize(Month value, JsonGenerator gen, SerializationContext context) {
gen.writeString(value.name());
}
});
return builder -> builder
.withConfigOverride(LocalDate.class,
o -> o.setFormat(JsonFormat.Value.forPattern("dd/MM/yyyy")))
.addModule(months);==== profile indian-dates (JsonMapperBuilderCustomizer)
spring.profiles.active=indian-dates
GET /event -> 200 {"day":"15/12/2026","wallClock":"2026-12-15T10:30:00","createdAt":"2026-12-15T05:00:00Z","startsAt":"2026-12-15T10:30:00+05:30","length":"PT1H30M","month":"NOVEMBER","legacy":"2026-12-15T05:00:00.000Z"}
POST /booking -> 200 {"received":"2026-12-15T05:00Z"}Going deeper: property binding and other options
The keys under spring.jackson.datatype.datetime are bound to the DateTimeFeature enum, so the flags in the earlier list can be set this way. Run everything with run-boot.sh; the complete transcript is output/13.
Migrating: what can read what?
Upgrades are rarely atomic. Caches, queues and other services hold payloads from before. T10StoredPayloads.java checks both directions with a record containing a Meeting, a Duration and a Month:
== old Jackson 2 payload, read by Jackson 3 defaults
{"meeting":{"day":[2026,12,15],"wallClock":[2026,12,15,10,30],"createdAt":1797310800.000000000,"startsAt":1797310800.000000000,"reminderAt":1797310800.000000000},"length":5400.000000000,"month":"DECEMBER"}
OK Job[meeting=Meeting[day=2026-12-15, wallClock=2026-12-15T10:30, createdAt=2026-12-15T05:00:00Z, startsAt=2026-12-15T05:00Z, reminderAt=2026-12-15T05:00Z], length=PT1H30M, month=DECEMBER]
== new Jackson 3 payload, read by a Jackson 2 consumer (defaults + module)
{"meeting":{"day":"2026-12-15","wallClock":"2026-12-15T10:30:00","createdAt":"2026-12-15T05:00:00Z","startsAt":"2026-12-15T10:30:00+05:30","reminderAt":"2026-12-15T10:30:00+05:30"},"length":"PT1H30M","month":12}
FAIL InvalidFormatException: Cannot deserialize value of type `java.time.Month` from number 12: index value outside legal index range [0..11]
== Jackson 3 told to keep writing the Jackson 2 shapes
{"meeting":{"day":[2026,12,15],"wallClock":[2026,12,15,10,30],"createdAt":1797310800.000000000,"startsAt":1797310800.000000000,"reminderAt":1797310800.000000000},"length":5400.000000000,"month":12}
identical to the Jackson 2 payload : false
FAIL InvalidFormatException: Cannot deserialize value of type `java.time.Month` from number 12: index value outside legal index range [0..11]Jackson 3 read the old numeric payload without any configuration. The other direction failed loudly here only because the sample month is December; as the Month section showed with November, other months are read as the wrong value. Enabling the two timestamp flags reproduces the old date shapes but, as the third block shows, still not the month. If you cannot upgrade consumers first, a practical order is:
- Delete the jsr310 dependency and registrations in the service you are upgrading.
- Search DTOs for
Monthandjava.sql.Date; fix both explicitly. - Decide whether consumers can parse ISO strings. If not, enable
WRITE_DATES_AS_TIMESTAMPSandWRITE_DURATIONS_AS_TIMESTAMPSuntil they can. - Compare real payloads from old and new builds in a test, not by eye.
- Check any
@JsonFormatpattern forYYYY, quoted'Z'and missing time zones while you are there.
Going deeper: a Jackson 2 consumer that must read 1-based months
Jackson 2’s jsr310 module has JavaTimeFeature.ONE_BASED_MONTHS; the line “Jackson 2 + ONE_BASED_MONTHS reads” in output/11 shows 2.23.0 reading Jackson 3’s number correctly with it (I ran only 2.23.0). It changes how that consumer treats numbers from everyone, so check its other producers.
What should you actually choose?
Keep the Jackson 3 defaults for output and be explicit about input. UseInstantfor timestamps andLocalDatefor calendar dates. Leave the mapper in UTC. DisableADJUST_DATES_TO_CONTEXT_TIME_ZONEonly if the sender’s offset matters. Write months by name. Use@JsonFormatonly where an external contract demands it, withuuuuandlenient = OptBoolean.FALSE.
Reach forbuilderWithJackson2Defaults()oruse-jackson2-defaultsas a temporary bridge, not a destination, and test the payloads either way.
Further reading
- java-time companion module with every program and transcript
- Jackson 2 to Jackson 3 migration guide
- Jackson 3 vs Jackson 2: the full comparison
- ObjectMapper and JsonMapper guide
- Jackson annotations guide
- Custom serializers and mix-ins
- java.util.Date and Calendar to java.time migration guide
- official Jackson 3 migration guide
- jackson-databind release notes
- Spring Boot reference: JSON
- DateTimeFormatter pattern letters (Java 25 API)
No Comments yet!