Class DmxValidator

java.lang.Object
dmx.fun.jakarta.validation.DmxValidator

@NullMarked public final class DmxValidator extends Object
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 Details

    • validate

      public static <T> Validated<NonEmptyList<String>, T> validate(jakarta.validation.Validator validator, T object, Class<?>... groups)
      Validates object and returns violation messages as a NonEmptyList<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 Validation Validator to use
      object - the object to validate
      groups - 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 - if validator or object is null
    • validateRaw

      public static <T> Validated<NonEmptyList<jakarta.validation.ConstraintViolation<T>>, T> validateRaw(jakarta.validation.Validator validator, T object, Class<?>... groups)
      Validates object and returns the raw ConstraintViolation set as a NonEmptyList.

      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 Validation Validator to use
      object - the object to validate
      groups - 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 - if validator or object is null