/
Validation Patterns
  • Working Draft
  • Validation Patterns

     

    Database schema and custom Micronaut validators

    We have dedicated migrations for defining the database schema.

    • It isn’t automatically generated from the java code model.

    • We use migration files for postgres to keep that inline with the model. So really it's 2 things that we make line up.

    • We never generate in production.

    There are validation api annotations and you can add custom validators.

    • The entities should be validated when passed to the various repositories.

    save( @Valid someEntity )
    • This ensures the validation routines are called on the model.

    • You should also get a validation exception should it fail.

     

    Validating that a property is not null

    @NonNull is a compiler and tooling suggestion whereas @NotNull  is a validation directive for validated classes.

    If you want to validate a property is not null make sure it also has the @NotNull variant.

    I would say rule of thumb, is that you either want both or just NonNull.

    Operated as a Community Resource by the Open Library Foundation