Dates are formatted with +0000 why not use Z

12 views
Skip to first unread message

Martin Lichtin

unread,
Apr 30, 2020, 12:53:47 PM4/30/20
to jackson-user
In StdDateFormat there's this comment

            // 24-Jun-2017, tatu: While `Z` would be conveniently short, older specs
            //   mandate use of full `+0000`
            // formatted.append('Z');

Wanted to ask if and why this is still relevant, as it seems to me it would be more natural to serialize using 'Z'.
Or perhaps offer a flag to control this as a serialization option.

Tatu Saloranta

unread,
Apr 30, 2020, 3:10:45 PM4/30/20
to jackson-user
Yes, ideally `Z` would (have been) used already.

Challenge is mostly about backwards compatibility: switch from "+0000"
to "+00:00" happens in 2.11; 3.x (`master`) would produce `Z`.
Beyond this while adding a configuration feature would be an option it
seems like a "too small" (or too datatype-specific) option to go as
either `DeserializationFeature` or `MapperFeature` (granted some
existing settings already go to minutiae).
Instead, `@JsonFormat` could work better, but this particular setting
is not really generic enough to work well there.

Beyond this, there are questions on uniformity (and lack thereof)
between date/time types: this code is only used for `java.util.Date` /
`Calendar`,
and most new code uses (and definitely should use) Joda date/time or
Java 8 date/time values. Their defaults are different.

On plus side this is a known problem area at least.

One possibility would be to perhaps create a new configuration type
(`DateTimeConfig`), configurable on `ObjectMapper`.
This is what I had in mind for JSTEP-5:

https://github.com/FasterXML/jackson-future-ideas/wiki/JSTEP-5

but have not had time to refine my thoughts (nor gotten much feedback).

Looking at various discussion on date/time, what I do know is that I
don't know enough of date/time handling
(and that Internet is full of people who do, or at least think, they
know much more :-D )

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages