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.

Solution: Add validation annotations

Solution: Add validation annotations

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

Start my 1-month free trial

Solution: Add validation annotations

- [Instructor] Okay, so how did you get in with this task? Well I imagine that your solution is gonna be slightly different to my solution, but let's have a look at what I've done. So you can see here that I've added to the id of the author, @NotNull, 'cause I don't want the id to ever be null. Now also you could add here a pattern like I've done to the blogURL, so that the id follows a particular pattern. Also for the firstName and lastName I've decided to have a minimum size of five, this may or may not be appropriate, and again you can also use a pattern to ensure that certain characters are not included in the firstName and lastName, numbers and other such characters. And what I've done for the blogURL is to add a regular expression, which validates that the blogURL is actually correct URL format. And as you can see it's exactly the same regular expression that I used in the book resource.

Contents