GitPedia

Java fluent validator

Java Fluent Validator is inspired by Fluent Interface and .Net FluentValidation which defined an inner-DSL within Java language for programmers to use. A fluent interface implies that its primary goal is to make it easy to SPEAK and UNDERSTAND.

From mvallim·Updated May 24, 2026·View on GitHub·

Validating data is a common task that occurs throughout any application, especially the business logic layer. As for some quite complex scenarios, often the same or similar validations are scattered everywhere, thus it is hard to reuse code and break the [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) rule. The project is written primarily in Java, distributed under the Apache License 2.0 license, first published in 2019. Key topics include: builder, fluent, fluent-api, fluent-interface, java.

Latest release: v1.10.1
<p align="center"><img src="documentation/fluent.png" height="20%" width="20%"></p>

Java Fluent Validator

Build, Publish Snapshot and Pull Request
Quality Gate Status
Coverage
Maven Central
Hex.pm

Validating data is a common task that occurs throughout any application, especially the business logic layer. As for some quite complex scenarios, often the same or similar validations are scattered everywhere, thus it is hard to reuse code and break the DRY rule.

Compatible JDK 8, 11, 15, 16 and 17

This library supports Kotlin aswell

Sample

Java

java
import static br.com.fluentvalidator.predicate.ComparablePredicate.equalTo; import static br.com.fluentvalidator.predicate.LogicalPredicate.not; import static br.com.fluentvalidator.predicate.ObjectPredicate.nullValue; import static br.com.fluentvalidator.predicate.StringPredicate.stringContains; import static br.com.fluentvalidator.predicate.StringPredicate.stringEmptyOrNull; import br.com.fluentvalidator.model.Boy import br.com.fluentvalidator.model.Gender; import br.com.fluentvalidator.AbstractValidator; public class JavaValidatorBoy extends AbstractValidator<Boy> { @Override protected void rules() { ruleFor(Boy::getGender) .must(equalTo(Gender.MALE)) .when(not(nullValue())) .withMessage("gender of boy must be MALE") .withFieldName("gender") .critical(); ruleFor(Boy::getName) .must(stringContains("John")) .when(not(stringEmptyOrNull())) .withMessage("child name must contains key John") .withFieldName("name"); } }

Kotlin

kotlin
import br.com.fluentvalidator.predicate.ComparablePredicate.equalTo; import br.com.fluentvalidator.predicate.LogicalPredicate.not; import br.com.fluentvalidator.predicate.ObjectPredicate.nullValue; import br.com.fluentvalidator.predicate.StringPredicate.stringContains; import br.com.fluentvalidator.predicate.StringPredicate.stringEmptyOrNull; import br.com.fluentvalidator.model.Boy import br.com.fluentvalidator.model.Gender; import br.com.fluentvalidator.AbstractValidator; class KotlinValidatorBoy : AbstractValidator<Boy> { constructor() : super(); override fun rules() { ruleFor(Boy::getGender) .must(equalTo(Gender.MALE)) .`when`(not(nullValue())) .withMessage("gender of boy must be MALE") .withFieldName("gender") .critical(); ruleFor(Boy::getName) .must(stringContains("John")) .`when`(not(stringEmptyOrNull())) .withMessage("child name must contains key John") .withFieldName("name"); } }

Index

  1. Quick start
  2. Validator
  3. Builder
  4. Predicate
  5. ValidationResult
  6. PredicateBuilder
  7. FunctionBuilder
  8. Examples

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use GitHub for versioning. For the versions available, see the tags on this repository.

Authors

  • Marcos Vallim - Founder, Author, Development, Test, Documentation - mvallim
  • Paulo Sergio - Manteiner, Development, Test, Documentation - paulosergio-jnr

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache License - see the LICENSE file for details

Contributors

Showing top 4 contributors by commit count.

View all contributors on GitHub →

This article is auto-generated from mvallim/java-fluent-validator via the GitHub API.Last fetched: 6/23/2026