Your SlideShare is downloading. ×
Flexible validation with Hibernate Validator 5.x.
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Flexible validation with Hibernate Validator 5.x.

400
views

Published on

by Yaroslav Hutsul

by Yaroslav Hutsul

Published in: Software, Technology, Business

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
400
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Iaroslav Gutsul
  • 2. What is value from validation? What is possible place for validation? What is right place for validation? What is correct implementation of validation?
  • 3. How to implement … with Hibernate Validator  simple bean validation  simple method validation  complex bean validation  custom constrain for validation
  • 4. What is with Hibernate Validator? • validation framework based on metadata model (annotations) • implements JSR 349 (Bean Validation 1.1) specification • provides under Apache Software License 2.0
  • 5. How to add Hibernate Validator to my project? Required Optional
  • 6. Basic bean validation  Field-level constraints  Property-level constraints  Class-level constraints  Constraint inheritance
  • 7. Cascade validation with @Valid
  • 8. Validator methods Validator#validate() Validator#validateProperty() Validator#validateValue()
  • 9. Built-in constraints @AssertFalse @Future @Max(value=) @Min(value=) @DecimalMax(value=, inclusive=) @NotNull @Valid @Size(min=, max=) @NotEmpty @Pattern(regex=, flag=)
  • 10. Declaring method constraints  Parameter constraints  Return value constraints Cross-parameter constraints
  • 11. Error Message default message custom message source
  • 12. Grouping constraints Validation group = java interface Add group to validation property Validation with group
  • 13. Grouping constraints combination @GroupSequence @GroupSequenceProvider (PROVIDER) PROVIDER implements DefaultGroupSequenceProvider<T> provide list of validation groups based on object stage @ConvertGroup(from = GROUP_A.class, to = GROUP_B.class) during validation with group A will be used rules from both groups
  • 14. Creating custom constraints Create a constraint annotation Implement a validator Define a default error message
  • 15. Create a constraint annotation with default error message
  • 16. Implement a validator
  • 17. ConstraintViolation Structure
  • 18. Interesting Notes  Fail fast mode  Boolean composition of constraints in custom constrain @ConstraintComposition(OR) CompositionType with its values AND, OR and ALL_FALSE. Validation of Null by default return true
  • 19. Thank you! Questions?

×