Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JSR 380 - Bean Validation 2.0

JSR 380 - Bean Validation 2.0

Slides of presentation from "Adopt-a-JSR for Java EE" Meeting on March 1st

Overview on history and current status of JSR 380 as well as opportunities for the community to contribute and participate

Gunnar Morling

March 01, 2017
Tweet

More Decks by Gunnar Morling

Other Decks in Technology

Transcript

  1. JSR 380 - BEAN VALIDATION 2.0 Adopt-a-JSR for Java EE

    Meeting, March 1st GUNNAR MORLING, RED HAT 1
  2. BEAN VALIDATION CONSTRAIN ONCE, VALIDATE EVERYWHERE! public class User {

    @NotNull @Email private String email; @Min(12) private int age; } Java SE + EE Integrated with JPA, JAX-RS, JSF Widely used: Spring MVC, GWT/Vaadin etc. 2
  3. BEAN VALIDATION 1.1 METHOD VALIDATION Automatically applied upon method invocation

    public class UserService { @NotNull public User createUser( @NotNull @Email String email, @Min(12) int age) { ... } } 3
  4. @Past(orPresent=true) private Year inceptionYear = Year.of( 2017 ); BEAN VALIDATION

    2.0 EMBRACE JAVA 8 Support for java.time API (JSR 310) 4
  5. @Past(orPresent=true) private Year inceptionYear = Year.of( 2017 ); BEAN VALIDATION

    2.0 EMBRACE JAVA 8 Support for java.time API (JSR 310) Repeatable annotations @Size(min = 8, group = Default.class) @Size(min = 12, group = Admin.class) private String password = ...; 5
  6. private Optional<String @Email> optionalEmail = ...; BEAN VALIDATION 2.0 CONSTRAINTS

    ON CONTAINER ELEMENTS java.util.Optional Collections @Size(min = 1) private List<@NotNull @Size(min = 5) String> names; 7
  7. private Optional<String @Email> optionalEmail = ...; BEAN VALIDATION 2.0 CONSTRAINTS

    ON CONTAINER ELEMENTS java.util.Optional Collections @Size(min = 1) private List<@NotNull @Size(min = 5) String> names; private Map<@Valid User, @Valid Address> addresses; 8
  8. private Optional<String @Email> optionalEmail = ...; BEAN VALIDATION 2.0 CONSTRAINTS

    ON CONTAINER ELEMENTS java.util.Optional Collections @Size(min = 1) private List<@NotNull @Size(min = 5) String> names; private Map<@Valid User, @Valid Address> addresses; Arrays, JavaFX's Property<T>, your own containers! 9
  9. CURRENT STATUS In Early Draft 1 Reference implementation: Hibernate Validator

    6.0 Alpha1 Implements ​ Early Draft 1 And more, e.g. support for lambda expressions ConstraintMapping constraintMapping = ...; constraintMapping .constraintDefinition( FileExists.class ) .validateType( File.class ) .with( f -> f.exists() ); 10
  10. GETTING INVOLVED Feedback, feedback, feedback! Try out container element constraints,

    value extractor API Join our mailing list Report bugs (and features) Spread the word Let's talk at conferences Devoxx US - March 21 - 23, San Jose JavaLand - March 28-30, Brühl, Germany Join the EG 11
  11. ALL IS OPEN SOURCE API, specification, TCK, web site Reference

    implementation Apache License 2.0 https://github.com/beanvalidation/ https://github.com/hibernate/hibernate-validator/ beanvalidation.org/contribute/ 12
  12. NEXT STEPS Converge on container element open issues Some new

    constraints (@NotEmpty, @Email etc.) Make message interpolation more re-usable YOUR requests Time line (Early draft 2 in next few weeks) Public Review in April/May Be there for Java EE 8 13
  13. RESOURCES Website: RI: Mailing list: Forum: Issue tracker: beanvalidation.org hibernate.org/validator

    http://lists.jboss.org/pipermail/beanvalidation- dev/ https://forum.hibernate.org/viewforum.php?f=26 https://hibernate.atlassian.net/browse/BVAL Get in touch: [email protected] @gunnarmorling 15