Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on Oct 22, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Kazuki Shimizu commented

    I've submitted PR. Please review.

  2. spring-projects-issues commented on Mar 12, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Note that the PR currently does not include a YearFormatter.

  3. spring-projects-issues commented on Mar 12, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  4. spring-projects-issues commented on Mar 12, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

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

  5. spring-projects-issues commented on Mar 12, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  6. spring-projects-issues commented on Mar 12, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.

  7. added
    type: enhancement
    in: core
    on Jan 11, 2019
  8. ioxua commented on Apr 1, 2020

    @ioxua

    Any reason this issue is frozen?

  9. onacit commented on Jan 24, 2021

    @onacit

    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]
    
  10. snicoll commented on Nov 24, 2021

    @snicoll
    Member

    Closing in favor of PR #1215

  11. added
    status: superseded
    on Nov 24, 2021
  12. removed this from the 6.x Backlog milestone on Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: corestatus: supersededtype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions