Validating an integer in java
The default values of system properties are set by the JVM upon startup and can be considered trusted.
However, they may be overridden by properties from untrusted sources, such as a configuration file.
For this example, we will create an object with three integer properties: one for the minimal value, one for the maximal value and one for the rating value, which we are restricting to be in between the minimal and maximal values. Annotations in Java are created as a special kind of interface, using the @interface keyword.
This interface declaration is recognized by the compiler and an anonymous implementation class and instance are created by run-time code.
The and they are required by the validation run-time implementation.
The name of the validator class must be the same as used in the The validation will be triggered automatically when any Rating object is persisted through Hibernate/JPA.
If you want a more complete introduction, it is recommended to read the Hibernate Validator reference guide.
The Java environment is composed of environment variables and system properties.
Many frameworks, however, offer integration with Bean Validation out of the box, e.g. In this case it is enough to annotate your POJOs with constraint annotations.
Validation will occur automatically at the appropriate life cycle phase of the used technology. That concludes the 5 minutes tour through the world of Hibernate Validator and Bean Validation.
It takes a single or list of values of the type Element Type, but we are only allowing our custom annotation to be applied to types, whether they be classes or interfaces.