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

@DateTimeFormat support for YearMonth, MonthDay, Year [SPR-14839] #19405

Closed
spring-projects-issues opened this issue Oct 22, 2016 · 9 comments
Closed
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 22, 2016

Kazuki Shimizu (@kazuki43zoo) opened SPR-14839 and commented

I hope to support the @DateTimeFormat annotation for Joda-Time's YearMonth, MonthDay, and Year types, analogous to the existing support for the corresponding JSR-310 types.

For example:

public class AccountForm {

    @DateTimeFormat(pattern="MM/uuuu")
    private YearMonth expirationMonth;

    @DateTimeFormat(pattern="M/d")
    private MonthDay dayOfBirth;

    // ...
}

Affects: 4.3.3

Issue Links:

Referenced from: pull request #1215

@spring-projects-issues
Copy link
Collaborator Author

Kazuki Shimizu commented

I've submitted PR. Please review.

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Note that the PR currently does not include a YearFormatter.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Indeed, I'm repurposing this ticket a bit: primarily for JSR-310 where Year is also a topic, with Joda-Time as a secondary target.

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

But... you just introduced org.springframework.format.datetime.standard.YearFormatter in Spring 5.0.4 -- right? ;-)

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Indeed but that ticket just covered parsing according to the default format, like we do for Period and Duration, without any declarative customization options. This ticket is about considering @DateTimeFormat custom pattern support for remaining types where this makes sense.

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

This ticket is about considering @DateTimeFormat custom pattern support for remaining types where this makes sense.

Indeed!

Thanks for pointing out the difference.

@ioxua
Copy link

ioxua commented Apr 1, 2020

Any reason this issue is frozen?

@onacit
Copy link

onacit commented Jan 24, 2021

Also, any reason why this PR doesn't cover for java.time.Month with it's value not as an enum?

// for numeric value
@NotNull @DateTimeFormat(pattern = "M") @PathVariable(name = PATH_NAME_MONTH) final Month month
Failed to convert value of type 'java.lang.String' to required type 'java.time.Month';
    nested exception is org.springframework.core.convert.ConversionFailedException:
        Failed to convert from type [java.lang.String] to type [@javax.validation.constraints.NotNull @org.springfr
amework.format.annotation.DateTimeFormat @org.springframework.web.bind.annotation.PathVariable java.time.Month] for value '11'; nested exception is java.lang.IllegalArgumentException: No enum constant java.time.Month.11]

@snicoll
Copy link
Member

snicoll commented Nov 24, 2021

Closing in favor of PR #1215

@snicoll snicoll closed this as completed Nov 24, 2021
@snicoll snicoll added the status: superseded An issue that has been superseded by another label Nov 24, 2021
@snicoll snicoll removed this from the 6.x Backlog milestone Nov 24, 2021
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) status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants