I'm writing tests for a bean that is a parameter in @RestController
's method.
Bean POJO:
public class AddTownRequestBean
{
@NotEmpty(message = "INVALID_REQUEST")
@Length(min = 1, max = 30, message = "PARAMETER_OUT_OF_BOUNDS")
private String name;
@NotEmpty(message = "INVALID_REQUEST")
@Length(min = 3, max = 4, message = "PARAMETER_OUT_OF_BOUNDS")
private String typeCreated;
@DateTimeFormat(pattern = "yyyy-MM-dd") //style = "S-", iso = DateTimeFormat.ISO.DATE,
private String foundationDate;
getters and setters...
}
My question is related to @DateTimeFormat
annotation. In documentation it is stated that this annotation:
Can be applied to java.util.Date, java.util.Calendar, Long (for millisecond timestamps) as well as JSR-310 java.time and Joda-Time value types.
As one can see, there's no support of simple String
type, but my POJO's date field is String
. I already tested using @DateTimeFormat
as outlined above, also with commented parameters, mutually excluded every time. And obviously it didn't work out.
So the question itself - is there any annotation or similar workaround to add a (let's call it) "validator" for specific date format in a String
type variable that's meant to be a date?