Skip to content

8.0.0-RC1: default JSON/XML DateMarshaller fails on java.sql.Date and drops .000 millis (undocumented change from 7.x) #16406

Closed

Description

@rodrigolimaivt

Expected Behavior

Rendering a java.sql.Date (or java.sql.Time) with as JSON / render ... as JSON works, as it does in Grails 7.x, and the default JSON date format stays yyyy-MM-dd'T'HH:mm:ss.SSS'Z' (or the change is listed in the upgrade guide).

Actual Behaviour

In 8.0.0-RC1 the default org.grails.web.converters.marshaller.json.DateMarshaller (and the XML one) formats with date.toInstant().

  1. java.sql.Date / java.sql.Time fail. They are subclasses of java.util.Date, so supports() returns true, but java.sql.Date#toInstant() and java.sql.Time#toInstant() always throw UnsupportedOperationException (JDK contract). The converter call fails and a controller rendering the value returns 500. In 7.x the FastDateFormat path formatted them fine. java.sql.Date shows up often in maps built from groovy.sql.Sql rows or native queries.
  2. The default output format changed. Since d3c82799f0 the default is DateTimeFormatter.ISO_INSTANT, which omits a zero fraction: a date with no milliseconds used to render as 2026-09-25T03:00:00.000Z and now renders as 2026-09-25T03:00:00Z (same for java.sql.Timestamp; dates with non-zero millis keep .123Z, so the output length now varies). Both are valid ISO 8601, but clients that parse with a fixed pattern (.SSS'Z') or compare strings break. The 8.0 upgrade guide does not mention it (the only "default date format" row is about Jackson 3).

toInstant() came in with 2fcf83213a (#15432, replacing FastDateFormat to fix the three-letter time zone warning). The format change came with d3c82799f0.

Steps To Reproduce

In any Grails 8.0.0-RC1 app, in a controller action:

render([d: java.sql.Date.valueOf('2026-09-25')] as grails.converters.JSON)
// Grails 8.0.0-RC1: RuntimeException caused by UnsupportedOperationException (HTTP 500 in a controller). Grails 7.2.3: {"d":"2026-09-25T03:00:00.000Z"} (JVM in America/Sao_Paulo)

render([d: new Date(1790305200000L)] as grails.converters.JSON)
// Grails 7.2.3: {"d":"2026-09-25T03:00:00.000Z"}
// Grails 8.0.0-RC1: {"d":"2026-09-25T03:00:00Z"}

Possible fix, for both JSON and XML marshallers:

Instant instant = date instanceof java.sql.Date || date instanceof java.sql.Time
        ? Instant.ofEpochMilli(date.getTime())
        : date.toInstant();

and either go back to a fixed .SSS pattern or add the format change to the upgrade guide.

Environment Information

  • Grails 8.0.0-RC1 (from the ASF staging repository)
  • JDK 21 (Temurin), Linux
  • Compared with the same app on Grails 7.2.3

Example Application

No response (the snippet above is enough to reproduce)

Version

8.0.0-RC1

Activity

  1. modified the milestones: , grails:8.0.0-RC2 on Sep 28, 2026
  2. added a commit that references this issue on Sep 28, 2026
    4d60dba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions