Validators

DOGs validators are based on retained annotation, which are nothing more the annotations which are retained at runtime. All of these annotations are const classes that extend StructureMetadata and implement either FieldValidator and/or ClassValidator.

The actual validation however is carried out by the Validatable instance associated with the object which shall be validated. Typically, converters implement the Validatable interface for the type which they can convert.

For a list of built in validators refer to 5. Validation

Validation Flow (DefaultStructureConverter)

All validators, no matter if it's FieldValidator or a ClassValidator, define the methods getCachedValue, validate and isApplicable. The getCachedValue method is intended to be used for inspecting the structure. After inspection, an immutable dataclass should be created by the getCachedValue which holds all necessary information for validating the field at runtime. The emitted value will then be reused for all following conversion passes.

At this point, neither a DogEngine nor a value are known to the validator and should not be accessed statically, circumventing safety guarantees.

When the validator is used by the Engine, the validate method gets called with the previously generated cached value, the object which must be validated and the calling DogEngine instance.

Last updated