spring-framework
spring-framework copied to clipboard
DateTimeFormatterRegistrar should use ISO formats by default
Affects: 5.3.7
Currently DateTimeFormatterRegistrar
behavior is different from default JDK
For example, given OffsetDateTime.parse(XXX)
, if XXX can be parsed this way, it should be parsed by DateTimeFormatterRegistrar
too.
Please note that changing the current behavior would be a breaking change.
The documentation for DateTimeFormatterRegistrar
states that it does not use ISO formatting by default, but that can be changed via DateTimeFormatterRegistrar#setUseIsoFormat(true)
.
Can you please provide more information regarding your exact use case?
Yes, I know setUseIsoFormat
. I create this issue to discussion is there any chance to change it to true by default.
The reason I already said in first comment. This option should be true by default.
About my real use case : I use RFC 3339 format in all time field in my rest api. It work well with json(jackson) without any config, the default config is good and standard. But when use it in query parameter, it fail.
But when use it in query parameter, it fail.
Have you tried annotating the corresponding parameter of your controller method with @DateTimeFormat(iso = ISO.DATE_TIME)
?
Yes, I can do that, but I want make it default without any config.
Thanks for the feedback, @abccbaandy.
Since changing the default would be a breaking change, we will revisit this topic for Spring Framework 6.
I've slightly repurposed this issue for revisiting our fallback parsing behavior there. Based on the scenario described above, we should indeed leniently accept the default parse
format of every java.time
type.
This is different from switching useIsoFormat
to true
since that affects printing as well and generally bypasses other style settings. Also, this new ISO fallback behavior only kicks in if no fallback patterns have been specified, so it's easy to bypass.
Related enhancements in 6.0: #1215, #19846