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

Allow strict LocalDate parsing #148

Closed
agusevas opened this issue Oct 29, 2019 · 5 comments
Closed

Allow strict LocalDate parsing #148

agusevas opened this issue Oct 29, 2019 · 5 comments
Labels
good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project

Comments

@agusevas
Copy link

Per default LocalDateDeserializer deserializes local dates using DateTimeFormatter.ISO_LOCAL_DATE formatter. This formatter uses ResolverStyle.STRICT.

    /**
     * Style to resolve dates and times strictly.
     * <p>
     * Using strict resolution will ensure that all parsed values are within
     * the outer range of valid values for the field. Individual fields may
     * be further processed for strictness.
     * <p>
     * For example, resolving year-month and day-of-month in the ISO calendar
     * system using strict mode will ensure that the day-of-month is valid
     * for the year-month, rejecting invalid values.
     */
    STRICT,

If I use @JsonFormat (i.e. @JsonFormat(pattern = "yyyy-MM-dd", lenient = OptBoolean.FALSE)) the created DateTimeFormatter uses ResolverStyle.SMART. It accepts invalid dates like 2019-11-31.
The default formatter does not accept such dates and throws an error.

To make the behaviour consistent, I suggest setting the DateTimeFormatter to use ResolverStyle.STRICT if the lenient attribute is set to false.

@cowtowncoder
Copy link
Member

Sounds reasonable, thank you for suggesting this!

@cowtowncoder cowtowncoder added the good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project label Oct 29, 2019
@cowtowncoder cowtowncoder changed the title Allow strict LocalDate parsing Allow strict LocalDate parsing Oct 29, 2019
@samwill
Copy link
Contributor

samwill commented Oct 30, 2019

I'd like to work on this!

@cowtowncoder
Copy link
Member

cowtowncoder commented Oct 30, 2019

@samwill sounds good to me -- PR can be made against master branch, or 2.11 (I can help merging regardless).

The best first step is probably adding a new unit test that shows the problem: I can actually merge that separately, even before/without fix. The only thing to note is that test should go under package that ends with failing, so it will not block build.

samwill pushed a commit to samwill/jackson-modules-java8 that referenced this issue Oct 30, 2019
@samwill
Copy link
Contributor

samwill commented Oct 30, 2019

Added a PR with a failing test. I think I know how to fix it now; given no hiccups I should have a fix PR tonight or tomorrow morning 🤞

kupci added a commit that referenced this issue Oct 31, 2019
samwill pushed a commit to samwill/jackson-modules-java8 that referenced this issue Oct 31, 2019
…ateTimeFormatter with ResolverStyle.STRICT when JsonFormat lenient = false
@cowtowncoder
Copy link
Member

@samwill Thank you again for the fix! Will be released in 2.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project
Projects
None yet
Development

No branches or pull requests

3 participants