JAX-RS and Bean Validation | Java.net
One of the newer features introduced in JAX-RS 2.0 is the support for validating resource classes with Bean Validation
Bean Validation support comes in Jersey 2.x by adding jersey-bean-validation module to the class-path.
The following sample shows how to use Bean Validation with JAX-RS 2.0. I show how to define a custom constraint which will validate any Enum class.
Additionally I will show code on how to use bean validation with Jersey 1.x which is a reference implementation for JAX-RS 1.0
I demonstrate a sample of a Coffee shop which can take orders for coffee and get details of a particular order. The following code shows a basic CoffeesResource. Consider placing an order for coffee and the choices to be made. In post cases these choices can be validated by using java.lang.Enum. So in this sample I have a simple Enum Validator which can validate all such constraints. Here are some of the choices for a coffee order
Read full article from JAX-RS and Bean Validation | Java.net
No comments:
Post a Comment