question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support fallback parsing patterns in @DateTimeFormat

See original GitHub issue

member sound opened SPR-15736 and commented

It would be nice if one could set multiple formats for:

@DateTimeFormat(pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyyMMdd")
@DateTimeFormat(pattern = "yyyy.MM.dd")
private LocalDate date;

https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html


No further details from SPR-15736

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sbrannencommented, Mar 2, 2021

Current work on this can be viewed in my feature branch: https://github.com/spring-projects/spring-framework/compare/master...sbrannen:issues/gh-20292-DateTimeFormat-patterns

The current approach is to introduce a new String[] fallbackPatterns() attribute that allows the user to specify a primary pattern for printing and parsing (via the existing style, iso, and pattern attributes) with multiple fallback patterns for parsing if the primary parsing pattern fails.

An example taken from the test suite:

@DateTimeFormat(pattern = "yyyy-MM-dd", fallbackPatterns = { "M/d/yy", "yyyyMMdd", "yyyy.MM.dd" })
private Date dateWithFallbackPatterns;
0reactions
membersoundcommented, Feb 26, 2021

That’s really a great idea. Well done!

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.time DateTimeFormatter parsing with flexible fallback ...
Imagine I want to parse the dateformat dd/MM , then I would need to add parseDefaulting(ChronoField.YEAR, 1984) to my formatter, knowing this ...
Read more >
DateTimeFormat (Spring Framework 6.0.2 API)
Fallback patterns are only used for parsing. They are not used for printing the value as a String. The primary pattern() , iso()...
Read more >
Intl.DateTimeFormat - JavaScript - MDN Web Docs
Chrome Edge DateTimeFormat Full support. Chrome24. Toggle history Full support. Edge12... DateTimeFormat() constructor Full support. Chrome24. Toggle history Full support. Edge12... locales parameter Full support. Chrome24....
Read more >
Formatting Dates and Times | ICU Documentation
Use a DateFormat to parse also: UErrorCode status = ZERO_ERROR; UDate myDate = df ...
Read more >
DateTimeFormat (GWT Javadoc)
When parsing a date string using the abbreviated year pattern ( "yy" ), the parser must interpret the abbreviated year relative to some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found