Skip to content

Conversation

codeconsole
Copy link
Contributor

@codeconsole codeconsole commented Oct 8, 2025

Fixes #15119

This makes consisteny across all formats and aligns with how Spring Boot 4 Jackson currently renders:

Type Has Time Zone? Serialized as Example
Instant Yes (always UTC) ISO-8601 with Z "2025-10-08T07:24:09.696Z"
OffsetDateTime Yes (custom offset) ISO-8601 with offset "2025-10-08T07:24:09.696-07:00"
ZonedDateTime Yes (zone) ISO-8601 with zone "2025-10-08T00:24:09.696-07:00[America/Los_Angeles]"
LocalDateTime No ISO-8601 without offset "2025-10-08T00:24:09.696"
Date Legacy UTC ISO-8601 with Z "2025-10-08T07:24:09.696Z"

Spring Boot 4:

  "date": "2025-10-08T07:48:46.407Z",
  "localDate": "2025-10-08",
  "localDateTime": "2025-10-08T00:48:46.407254",
  "instant": "2025-10-08T07:48:46.407254Z",
  "offsetDateTime": "2025-10-08T00:48:46.407254-07:00",
  "zonedDateTime": "2025-10-08T00:48:46.407254-07:00",

Grails After this PR:

{

  "calendar": "2025-10-08T07:48:46.407Z",
  "date": "2025-10-08T07:48:46.407Z",
  "localDate": "2025-10-08",
  "localDateTime": "2025-10-08T00:48:46.407254",
  "instant": "2025-10-08T07:48:46.407254Z",
  "offsetDateTime": "2025-10-08T00:48:46.407254-07:00",
  "zonedDateTime": "2025-10-08T00:48:46.407254-07:00"
}

@codeconsole codeconsole changed the title Use consistent ISO-8601 formatting for rendering JSON Date, LocalDateTime, and Instant properties Use consistent ISO-8601 formatting for rendering JSON Date, Calendar, LocalDateTime, and Instant properties Oct 8, 2025
@sbglasius
Copy link
Contributor

@codeconsole Please see why the Code style fails

@sbglasius sbglasius added this to the grails:7.0.0 milestone Oct 8, 2025
@codeconsole
Copy link
Contributor Author

@codeconsole Please see why the Code style fails

I forgot to commit the newly added Calendar marshaller.

@jdaugherty
Copy link
Contributor

This is a breaking change and we did not plan to do another RC. We need to discuss this PR at the weekly to merge it

@jdaugherty
Copy link
Contributor

Per weekly meeting, we'll merge after @matrei reviews.

Copy link
Contributor

@matrei matrei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid! Nice work Scott 👍

I identified a possibility to drop commons-lang3 from grails-converters in Grails 8 by replacing FastDateFormat with stock Java DateTimeFormatter.

@Override
Object convert(Object value, String key) {
DateTimeFormatter.ISO_ZONED_DATE_TIME.format((ZonedDateTime) value)
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format((ZonedDateTime) value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment why we are using ISO_OFFSET_DATE_TIME instead of ISO_ZONED_DATE_TIME formatter?

Copy link
Contributor Author

@codeconsole codeconsole Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matrei in order to match Spring Boot Jackson output:

ZonedDateTime value = ZonedDateTime.now()
println DateTimeFormatter.ISO_ZONED_DATE_TIME.format((ZonedDateTime) value)
println DateTimeFormatter.ISO_OFFSET_DATE_TIME.format((ZonedDateTime) value)
2025-10-09T17:27:04.791062156Z[UTC]
2025-10-09T17:27:04.791062156Z

Spring Boot produces "zonedDateTime": "2025-10-08T00:48:46.407254-07:00",

public void marshalObject(Object object, JSON converter) throws ConverterException {
try {
ZonedDateTime zonedDateTime = (ZonedDateTime) object;
converter.getWriter().value(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(zonedDateTime));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment why we are using ISO_OFFSET_DATE_TIME instead of ISO_ZONED_DATE_TIME formatter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matrei see comment above

@codeconsole codeconsole merged commit a87a2e7 into apache:7.0.x Oct 9, 2025
36 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.

7.0.0-RC2: Inconsistent Json Formatting between Date, LocalDateTime and Instant
4 participants