Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTimeFormatterRegistrar should fall back to ISO parsing by default #26985

Closed
abccbaandy opened this issue May 27, 2021 · 7 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@abccbaandy
Copy link

abccbaandy commented May 27, 2021

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 27, 2021
@sbrannen sbrannen changed the title DateTimeFormatterRegistrar should use iso format by default DateTimeFormatterRegistrar should use ISO formats by default May 27, 2021
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label May 27, 2021
@sbrannen
Copy link
Member

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?

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label May 27, 2021
@abccbaandy
Copy link
Author

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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 27, 2021
@sbrannen
Copy link
Member

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)?

@sbrannen sbrannen added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels May 27, 2021
@abccbaandy
Copy link
Author

Yes, I can do that, but I want make it default without any config.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 27, 2021
@sbrannen sbrannen added status: pending-design-work Needs design work before any code can be developed and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 27, 2021
@sbrannen sbrannen added this to the 6.0 M1 milestone May 27, 2021
@sbrannen
Copy link
Member

Thanks for the feedback, @abccbaandy.

Since changing the default would be a breaking change, we will revisit this topic for Spring Framework 6.

@sbrannen sbrannen modified the milestones: 6.0.0-M5, 6.0.0-M6 Jun 7, 2022
@sbrannen sbrannen modified the milestones: 6.0.0-M6, 6.0.0-RC1 Aug 29, 2022
@jhoeller jhoeller self-assigned this Oct 11, 2022
@jhoeller jhoeller modified the milestones: 6.0.0-RC1, 6.0.0-RC2 Oct 11, 2022
@jhoeller jhoeller changed the title DateTimeFormatterRegistrar should use ISO formats by default DateTimeFormatterRegistrar should fall back to ISO parsing by default Oct 18, 2022
@jhoeller
Copy link
Contributor

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.

@jhoeller jhoeller removed the status: pending-design-work Needs design work before any code can be developed label Oct 18, 2022
@jhoeller
Copy link
Contributor

Related enhancements in 6.0: #1215, #19846

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants