Hi Tatu,
Thank you for your work on Jackson.
Could I propose date/time classes (in particular java.time.*) serialise as RFC 3339 / ISO 8601 interchange format by default for Jackson 3, and not as an epoch second, milli, micro or nano, etc.
It is the recommended practice by many in the industry (E.g. Google / Microsoft / json-schema validation, see links below) that RFC 3339 / ISO 8601 be used for the serialisation format for date/times in JSON and in particular JSON REST API design.
It is also generally the default format used by
java.time.* .toString() and
.parse() methods.
RFC 3339 / ISO 8601, I would say, is a better format than an epoch as
- it is human readable
- can preserve timezone information
- has nano precision
- has a maximum timestamp value that is not limited by the bit-length of a double/long (platform specific) and
- does not have unambiguous precision when inspecting the value (milli/micro, etc).
Additionally, is a more intuitive format for serialising LocalDate, rather than the current default of a JSON numeric array of
[year, month, day]Speaking from my experience, its seems a common source of bugs for developers not realising that either overriding global config defaults (e.g. disable
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) or field level annotations (
@JsonFormat(shape = STRING)) are necessary (or possible) to serialise as such.
Other frameworks may for instance try to do this already, for example
Spring Boot's JacksonAutoConfiguration does this by default.
I did see
JSTEP-2: Changes to date/time defaults and
JSTEP-5: Unify Date/Time handling but it seems it hadn't come to a firm conclusion what the default behaviour for date time serialisation in Jackson should be.
Thanks for your consideration.
References which consider RFC 3339 / ISO 8601 for datetime: