From the course: Java EE: RESTful Service with JAX-RS 2.0

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Work with Bean Validation

Work with Bean Validation

From the course: Java EE: RESTful Service with JAX-RS 2.0

Start my 1-month free trial

Work with Bean Validation

- [Instructor] Okay, let's start by annotating the book resource entity. I'm gonna open the book resource, and scroll down to where we have the fields. So the first field I'm going to annotate with the constraint is the ID field. This should be no longer or shorter than 10 characters. So we can use the size annotation and specify a minimum and maximum of 10. This will ensure that any string longer or shorter than 10 will result in a constraint violation. So we start by annotating, using the size annotation. And we start by entering in a min value as 10, and the max value as 10. And there we have it, we've configured that our ID cannot be longer or shorter than 10 characters. Let's move on and have a look at the title field. Now I want to annotate the title field, which I want to be at least five characters in length, so here I set the minimum value. So I start again, with my size annotation, and I simply pass in the min value, which is going to be five. And the description, I want to…

Contents