how to validate data types in java?

hi I want to validate the data types in the java code . How should I go about it? The data types include String buffer,int , String etc.It would be nice if you could bring the use of validator class here.

Answer

Use hibernate validator and annotate your fields with the kind of types they are supposed to be.

For example

class Datas {

@Pattern(regexp("[a-z]"))
private String here;
@Id
@NotNull
private Integer num;

//
}  

Here you are saying ‘here’ is allowed to only contain a-z characters and num is an Integer that may not be null. Is something like this what you want? To validate input/output of your data-model ?

Leave a Reply

Your email address will not be published. Required fields are marked *