Files
cbsnexora-backend/docs/developers/validation.md
T

1.0 KiB

Validation

Programmatic

Use the DataValidatorBuilder, e.g. like so:

new DataValidatorBuilder().resource("fileUpload")
    .reset().parameter("Content-Length").value(contentLength).notBlank().integerGreaterThanNumber(0)
    .reset().parameter("FormDataContentDisposition").value(fileDetails).notNull()
    .throwValidationErrors();

Such code is often encapsulated in *Validator classes (if more than a few lines, and/or reused from several places; avoid copy/paste), like so:

public class YourThingValidator {

    public void validate(YourThing thing) {
        new DataValidatorBuilder().resource("yourThing")
        ...
        .throwValidationErrors();
    }
}

Declarative

FINERACT-1229 is an open issue about adopting Bean Validation for declarative instead of programmatic (as above) validation. Contributions welcome!