rodrigolimaivt opened a new issue, #16406:
URL: https://github.com/apache/grails-core/issues/16406
### 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:
```groovy
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:
```java
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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]