Simplifies base validator implementation.
Simplifies base validator implementation. Validators typically consist of an assertion/test and a resulting violation; this implementation takes two functions that describe this behavior and wires the appropriate logic. For example:
class IsNull extends BaseValidator[ AnyRef ]( _ == null, _ -> "is not a null" )
The object type this validator operates on.
An object representing a failed validation result.
An object representing a failed validation result.
The violations that caused the validation to fail.
Describes the violation of a group of constraints.
Describes the violation of a group of constraints. For example, the Or
combinator found in the built-in
combinator library produces a group violation when all of its predicates fail.
The value of the object which failed validation.
A textual description of the constraint being violated (for example, "doesn't meet any of the requirements").
The set of violations contained within the group.
The path to the object under validation.
A base validator implementation that, depends on the specified type's nullability, checks for null values prior to executing the specified test.
A base validator implementation that, depends on the specified type's nullability, checks for null values prior to executing the specified test.
The object type this validator operates on.
An extension to com.wix.accord.BaseValidator that transparently fails on nulls.
An extension to com.wix.accord.BaseValidator that transparently fails on nulls.
The object type this validator operates on.
A type class that indicates whether or not a type is nullable.
A type class that indicates whether or not a type is nullable.
The type for which nullability is indicated.
A base trait for validation results.
A base trait for validation results.
Describes a simple validation rule violation (i.e.
Describes a simple validation rule violation (i.e. one without hierarchy). Most built-in combinators emit this type of violation.
The value of the object which failed the validation rule.
A textual description of the constraint being violated (for example, "must not be empty").
The path to the object under validation.
A validator over some type T
.
A validator over some type T
.
An Accord validator is a function T => Result
, where T
is the type of the object under validation
and Result is an instance of com.wix.accord.Result.
Implementation note: While theoretically a validator can be defined as a type alias, in practice this doesn't allow to specify an error message when it's implicitly missing at the call site.
The object type this validator operates on.
A base trait for all violation types.
Provides a convenience DSL for generating violations:
Provides a convenience DSL for generating violations:
- Rule violations can be created by specifying a value and constraint message as a tuple, for example:
v -> "must not be empty"
- Group violations can be created by extending the above to include children, as in:
v -> "does not match any of the rules" -> Seq( v.firstName -> "first name must be empty", ... )
An object representing a successful validation result.
A companion object mostly responsible for allowing null-safe validation of boxed Java primitive types.
Validates the specified object and returns a validation com.wix.accord.Result.
Validates the specified object and returns a validation com.wix.accord.Result. An implicit com.wix.accord.Validator must be in scope for this call to succeed.
The type of the object to validate.
The object to validate.
A validator for objects of type T
.
A com.wix.accord.Result indicating success or failure of the validation.
Provides alternative syntax for validation.
Provides alternative syntax for validation. Instead of having to explicitly call
com.wix.accord.validate, an object can be validated by calling
instanceUnderTest.validate
. This is strictly an aesthetic preference, there are
no differences in implementation or execution.
(Since version 0.7) Will be removed in subsequent releases; you can reimplement this easily if needed.
The entry-point to the Accord library.
Overview
An Accord validator is a typeclass, which adds data validation rules over an existing domain model. The
api
module deals with the usage site; details on how to define validators can be found in thecore
module.To use a validator, simply import this package, make sure the validator is in scope and use the validate function:
See Result, Success and Failure for details of the result model.