I have below property in POJO class for DoB.
@NotNull(message = "dateOfBirth is required")
@JsonDeserialize(using = LocalDateDeserializer.class)
LocalDate dateOfBirth;
How can I validate that
- User is sending valid date format (accepting only YYYY-MM-DD)
- If user enters incorrect date I want to send custom message or more readable message. Currently if user entered invalid date then application sends below long error -
JSON parse error: Cannot deserialize value of type `java.time.LocalDate` from String \"1984-33-12\": Failed to deserialize java.time.LocalDate:
(java.time.format.DateTimeParseException) Text '1984-33-12' could not be parsed: Invalid value for MonthOfYear (valid values 1 - 12): 33;
...
yyyy-MM-dd
oruuuu-MM-dd
. Check the documentation to learn the difference betweenY
andy
, and betweenD
andd
. – Boult