Skip to content

Add DateTimeFeature.ALWAYS_WRITE_SUBSECOND_DIGITS - #6151

Merged
cowtowncoder merged 7 commits into
FasterXML:3.xfrom
seonwooj0810:always-write-subsecond-digits
Aug 11, 2026
Merged

Add DateTimeFeature.ALWAYS_WRITE_SUBSECOND_DIGITS#6151
cowtowncoder merged 7 commits into
FasterXML:3.xfrom
seonwooj0810:always-write-subsecond-digits

Conversation

@seonwooj0810

Copy link
Copy Markdown
Contributor

Adds DateTimeFeature.ALWAYS_WRITE_SUBSECOND_DIGITS: when enabled, Instant, OffsetDateTime, ZonedDateTime and LocalDateTime always serialize with at least millisecond-precision sub-second digits (zero-padded), instead of the JDK-provided ISO formatters omitting the field entirely when it's zero.

Fixes the same underlying issue as modules-java8#76, where e.g. Instant.parse("2017-09-14T04:28:48.000Z") serializes as "2017-09-14T04:28:48Z" (no .000), breaking systems that expect fixed-width timestamps or that sort them lexicographically.

This ports the 2.x feature of the same name added in modules-java8#386, adapted to 3.x's architecture:

  • 2.x bakes the formatter into each serializer instance at module-setup time (JavaTimeModule.setupModule() calling withFeatures(JacksonFeatureSet<JavaTimeFeature>)).
  • 3.x already has a config-time-immutable, per-call ctxt.isEnabled(DateTimeFeature.XXX) pattern for date/time flags (see TRUNCATE_TO_MSECS_ON_WRITE), so this follows that pattern instead — no changes needed to JavaTimeInitializer.

Scope, matching the 2.x feature: Instant, OffsetDateTime, ZonedDateTime, LocalDateTime. LocalTime/OffsetTime have the same zero-fraction omission but are out of scope here, to match the ported feature's scope.

Only affects the default (no explicit formatter) textual serialization path; an explicit DateTimeFormatter / @JsonFormat pattern still wins, and numeric-timestamp serialization is unaffected.

Ports the 2.x JavaTimeFeature of the same name (modules-java8#386) to
3.x's ctxt.isEnabled(...) pattern already used by
TRUNCATE_TO_MSECS_ON_WRITE, rather than the 2.x
withFeatures(JacksonFeatureSet) module-setup wiring.

When enabled, Instant/OffsetDateTime/ZonedDateTime/LocalDateTime always
serialize with at least millisecond-precision sub-second digits instead
of omitting the field when it's zero. Explicit formatters/patterns and
numeric-timestamp serialization are unaffected.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.91% 📈 +0.010%
Branches branches 75.52% 📈 +0.020%

Coverage data generated from JaCoCo test results

Comment thread release-notes/CREDITS Outdated
@cowtowncoder cowtowncoder changed the title Add DateTimeFeature.ALWAYS_WRITE_SUBSECOND_DIGITS Add DateTimeFeature.ALWAYS_WRITE_SUBSECOND_DIGITS Aug 11, 2026
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.91% 📈 +0.010%
Branches branches 75.52% 📈 +0.020%

Coverage data generated from JaCoCo test results

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.91% 📈 +0.010%
Branches branches 75.52% 📈 +0.020%

Coverage data generated from JaCoCo test results

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.91% 📈 +0.010%
Branches branches 75.52% 📈 +0.020%

Coverage data generated from JaCoCo test results

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.91% 📈 +0.010%
Branches branches 75.53% 📈 +0.030%

Coverage data generated from JaCoCo test results

@cowtowncoder cowtowncoder added this to the 3.3.0 milestone Aug 11, 2026
@gitar-bot

gitar-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Adds DateTimeFeature.ALWAYS_WRITE_SUBSECOND_DIGITS to ensure Instant, OffsetDateTime, ZonedDateTime, and LocalDateTime always serialize with zero-padded millisecond precision. No issues found.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 81.91% 📈 +0.010%
Branches branches 75.52% 📈 +0.020%

Coverage data generated from JaCoCo test results

@cowtowncoder
cowtowncoder merged commit 8694305 into FasterXML:3.x Aug 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants