Iaroslav Gutsul
What is value from validation?
What is possible place for validation?
What is right place for validation?
What is correct ...
How to implement … with Hibernate
Validator
 simple bean validation
 simple method validation
 complex bean validation
...
What is with Hibernate Validator?
• validation framework based on metadata model (annotations)
• implements JSR 349 (Bean ...
How to add Hibernate Validator to my
project?
Required
Optional
Basic bean validation
 Field-level constraints
 Property-level constraints
 Class-level constraints
 Constraint inheri...
Cascade validation with @Valid
Validator methods
Validator#validate()
Validator#validateProperty()
Validator#validateValue()
Built-in constraints
@AssertFalse
@Future
@Max(value=)
@Min(value=)
@DecimalMax(value=,
inclusive=)
@NotNull
@Valid
@Size(...
Declaring method constraints
 Parameter constraints
 Return value constraints
Cross-parameter constraints
Error Message
default message
custom message source
Grouping constraints
Validation group = java interface
Add group to validation property
Validation with group
Grouping constraints combination
@GroupSequence
@GroupSequenceProvider (PROVIDER)
PROVIDER implements DefaultGroupSequen...
Creating custom constraints
Create a constraint annotation
Implement a validator
Define a default error message
Create a constraint annotation with
default error message
Implement a validator
ConstraintViolation Structure
Interesting Notes
 Fail fast mode
 Boolean composition of constraints in custom constrain
@ConstraintComposition(OR)
Com...
Thank you!
Questions?
Upcoming SlideShare
Loading in …5
×

Flexible validation with Hibernate Validator 5.x.

1,235 views

Published on

by Yaroslav Hutsul

Published in: Software, Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,235
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Flexible validation with Hibernate Validator 5.x.

  1. 1. Iaroslav Gutsul
  2. 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. 3. How to implement … with Hibernate Validator  simple bean validation  simple method validation  complex bean validation  custom constrain for validation
  4. 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. 5. How to add Hibernate Validator to my project? Required Optional
  6. 6. Basic bean validation  Field-level constraints  Property-level constraints  Class-level constraints  Constraint inheritance
  7. 7. Cascade validation with @Valid
  8. 8. Validator methods Validator#validate() Validator#validateProperty() Validator#validateValue()
  9. 9. Built-in constraints @AssertFalse @Future @Max(value=) @Min(value=) @DecimalMax(value=, inclusive=) @NotNull @Valid @Size(min=, max=) @NotEmpty @Pattern(regex=, flag=)
  10. 10. Declaring method constraints  Parameter constraints  Return value constraints Cross-parameter constraints
  11. 11. Error Message default message custom message source
  12. 12. Grouping constraints Validation group = java interface Add group to validation property Validation with group
  13. 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. 14. Creating custom constraints Create a constraint annotation Implement a validator Define a default error message
  15. 15. Create a constraint annotation with default error message
  16. 16. Implement a validator
  17. 17. ConstraintViolation Structure
  18. 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. 19. Thank you! Questions?

×