Class DmxValidator
java.lang.Object
dmx.fun.jakarta.validation.DmxValidator
dmx-fun adapter for Jakarta Bean Validation.
Validates objects using a Validator and returns a dmx-fun
Validated type instead of throwing ConstraintViolationException.
Violations accumulate into a NonEmptyList, preserving all constraint
failures for the caller to inspect.
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
// Messages only — "propertyPath: message" strings, sorted for determinism
Validated<NonEmptyList<String>, CreateItemRequest> r1 =
DmxValidator.validate(validator, request);
// Full ConstraintViolation detail
Validated<NonEmptyList<ConstraintViolation<CreateItemRequest>>, CreateItemRequest> r2 =
DmxValidator.validateRaw(validator, request);
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Validated<NonEmptyList<String>, T> Validatesobjectand returns violation messages as aNonEmptyList<String>.static <T> Validated<NonEmptyList<jakarta.validation.ConstraintViolation<T>>, T> validateRaw(jakarta.validation.Validator validator, T object, Class<?>... groups)
-
Method Details
-
validate
public static <T> Validated<NonEmptyList<String>, T> validate(jakarta.validation.Validator validator, T object, Class<?>... groups) Validatesobjectand returns violation messages as aNonEmptyList<String>.Each message has the form
"propertyPath: constraintMessage"for property-level constraints. For class-level constraints (where the property path is empty), only the constraint message is returned without a path prefix. Messages are sorted alphabetically for deterministic ordering across JVM runs.- Type Parameters:
T- the type of the object being validated- Parameters:
validator- the Jakarta ValidationValidatorto useobject- the object to validategroups- the validation groups to apply; empty means the default group- Returns:
Valid(object)when all constraints pass,Invalid(NonEmptyList.of(messages))when at least one is violated- Throws:
NullPointerException- ifvalidatororobjectisnull
-
validateRaw
public static <T> Validated<NonEmptyList<jakarta.validation.ConstraintViolation<T>>, T> validateRaw(jakarta.validation.Validator validator, T object, Class<?>... groups) Validatesobjectand returns the rawConstraintViolationset as aNonEmptyList.Violations are sorted by property path for deterministic ordering. Use this method when the caller needs to inspect constraint metadata (annotation type, interpolated message template, leaf bean, etc.).
- Type Parameters:
T- the type of the object being validated- Parameters:
validator- the Jakarta ValidationValidatorto useobject- the object to validategroups- the validation groups to apply; empty means the default group- Returns:
Valid(object)when all constraints pass,Invalid(NonEmptyList.of(violations))when at least one is violated- Throws:
NullPointerException- ifvalidatororobjectisnull
-