$ git clone https://github.com/manojseth55/springboot-rest-api-validation.git
File -> Import -> Maven -> Existing Maven Projects -> Browse Project from cloned location
Once Sprint Boot Application will be started successfully then we can call following Endpoints by using POSTMAN
http://localhost:8080/users
{
"name": "Mathew",
"dateOfBirth": "2022-07-30T17:19:19.570+00:00"
}
{
"name": "M",
"dateOfBirth": "2022-07-30T17:19:19.570+00:00"
}
will get validation failed error
{
"timestamp": "2022-07-31T05:56:01.236+00:00",
"message": "Method Argument Validation Failed",
"details": "org.springframework.validation.BeanPropertyBindingResult: 1 errors\nField error in object 'user' on field
'name': rejected value [a]; codes [Size.user.name,Size.name,Size.java.lang.String,Size];
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.name,name];
arguments [];default message [name],2147483647,2]; default message [name must have at least 2 character!]"
}
{
"name": "Mathew",
"dateOfBirth": "2025-07-30T17:19:19.570+00:00"
}
will get validation failed error
{
"timestamp": "2022-07-31T08:23:41.480+00:00",
"message": "Method Argument Validation Failed",
"details": "org.springframework.validation.BeanPropertyBindingResult: 1 errors\nField error in object 'user' on field
'dateOfBirth': rejected value [Wed Jul 30 25:03:56 IST 2025];
codes [Past.user.dateOfBirth,Past.dateOfBirth,Past.java.util.Date,Past];
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.dateOfBirth,dateOfBirth];
arguments []; default message [dateOfBirth]]; default message [date of birth should be past date from current date!]"
}
The annotated element must be false. Supported types are boolean and Boolean.
The annotated element must be true. Supported types are boolean and Boolean.
The annotated element must be a number whose value must be lower or equal to the specified maximum.
The annotated element must be a number whose value must be higher or equal to the specified maximum.
The annotated element must be a number within accepted range. and null elements are considered valid.
The string has to be a well-formed email address. Exact semantics of what makes up a valid email address are left to Jakarta Bean Validation providers. Accepts CharSequence. null elements are considered valid.
The annotated element must be an instant, date or time in the future.
The annotated element must be an instant, date or time in the present or in the future.
The annotated element must be a number whose value must be lower or equal to the specified maximum.
The annotated element must be a number whose value must be higher or equal to the specified maximum.
The annotated element must be a strictly negative number (i.e. 0 is considered as an invalid value).
The annotated element must be a negative number or 0.
The annotated element must not be null and must contain at least one non-whitespace character. Accepts CharSequence.
The annotated element must not be null nor empty.
The annotated element must not be null. Accepts any type.
The annotated element must be null. Accepts any type.
The annotated element must be an instant, date or time in the past.
The annotated element must be an instant, date or time in the past or in the present.
The annotated CharSequence must match the specified regular expression. The regular expression follows the Java regular expression conventions see java.util.regex.Pattern.
The annotated element must be a strictly positive number (i.e. 0 is considered as an invalid value).
The annotated element must be a positive number or 0.
The annotated element size must be between the specified boundaries (included).