I hope you're fine:
public class UserDTO extends AbstractDTO implements Serializable {
private static final long serialVersionUID = -2724997313065531109L;
@NotNull
@Pattern(regexp = "^[a-zA-Z0-9_\\.]+$")
@Length(min = 3, max = 30)
private String userName;
@NotNull
@Email
@Length(min = 3, max = 30)
private String email;
@NotNull
@Length(min = 6, max = 30)
private String password;
private String gender;
@Digits(fraction = 0, integer = 13)
@Length(min = 8, max = 20)
private String mobile;
@Length(min = 6, max = 30)
private String confirmPassword;
@NotNull
@Past
private Date birthDate;
I'm using Jackson to submit JSON object in Spring MVC, moreover I'm using Hibernate Validator.
For the above DTO, when I'm trying to submit a json object with username length is less than the minimum length in the class @Length(min = 3, max = 30), I got http 400 bad request. Why the annotation of hibernate validation is tightly coupled with Jackson? and How can I get rid of this error?
Thank you in advance :D
In the following link: http://ppettitau.wordpress.com/tag/requestbody/ ,You will find how to combine Hibernate Validator, Jacson, and Spring MVC. The link is providing a complete request life cycle, the client sends request and receive a response in AJAX way. The response contains the error messages that you want to show for the user.