Open sbeins55 opened 2 years ago
I wouldn't mind contributing a PR for this as I think I found what's happening.
It looks like the type converter uses a SimpleDateFormat which by default uses lenient parsing. The lenient parsing seems to be causing the auto downgrades.
Only reason I'm hesitant to open a PR is I'm no longer 100% certain that an invalid query parameter should throw a bad request, but maybe make it null? I'm also thinking lenient parsing is sometimes desired so this should be a configuration with the default being the current behavior?
bad request makes sense to me unless it is @Nullable
PRs welcome
@sbeins55 Agreed - making it configurable with the default being the current behavior
Expected Behavior
When sending an invalid date string to a controller with
@Format
the controller should respond with a Bad Request if the QueryValue is not valid for the expected type.Actual Behaviour
Invalid dates can be downgraded
2021-02-31 -> 2021-02-28
or just become null2021-02-32 -> null
Steps To Reproduce
The repo below shows this behavior in the test cases.
@Format("yyyy-MM-dd") @QueryValue test: LocalDate
Environment Information
Example Application
https://github.com/sbeins55/date-parsing
Version
3.0.3