javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Integer
Hope you're using validation in hibernate like this,
@NotBlankprivate Date some;
@NotBlank
is for String type. There is no concept of java.util.Date
being blank. It can be null or not null.. Use @NotNull
instead,
@NotNull@DateTimeFormat(pattern = "dd-mm-yyyy")private Date dateOfBirth;
See Balus answer and @NotBlank for more details.
Update
HTTP Status 400: The request sent by the client was syntactically incorrect.
For the above error in Date type try add @DateTimeFormat
annotation and mention the format of date you giving as input (say yyyy-mm-dd
). Like below,
@RequestMapping(value="/fetch" , method=RequestMethod.GET)public @ResponseBody String fetchResult(@RequestParam("from") @DateTimeFormat(pattern="yyyy-MM-dd") Date fromDate) { //Content goes here}
well if you are not using any framework like spring mvc or controller , then you have to do it your self. Request parameter is always sent as string to server side. Now whether some frame work can do it before request arrives into your controller as part of your interceptor. Otherwise you have to do it manually after getting request.getParameter("param_name")
If you want to restrict the input that is entered by the user, you will have to use Javascript to restrict the input type (You can use jQuery validator plugin for this).
Or else, if you want to convert the input entered by the user to integer and date, in your form action (servlet, perhaps), you will need to parse the integer using
Integer.parseInt(request.getParameter("integer_field_name"));
as for Date, use SimpleDateFormat API.
References: