Skip to content

Allow strict LocalDate parsing #148

@agusevas

Description

@agusevas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssue that seems easy to resolve and is likely a good candidate for contributors new to project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions