• Stars
    star
    154
  • Rank 242,095 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

Java Fluent Validator

Java CI with Maven CodeQL 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

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

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

More Repositories

1

kubernetes-under-the-hood

This tutorial is someone planning to install a Kubernetes cluster and wants to understand how everything fits together.
Shell
465
star
2

live-custom-ubuntu-from-scratch

(Yes, the project is still alive πŸ˜ƒ) This procedure shows how to create a bootable and installable Ubuntu Live (along with the automatic hardware detection and configuration) from scratch.
Shell
394
star
3

emv-qrcode

Java Based EMV QR Code Generator and Parser (MPM, CPM)
Java
96
star
4

cloud-image-ubuntu-from-scratch

This procedure shows how to create a cloud image Ubuntu from scratch to run on Cloud environments (EC2, GCE, Azure, QEMU and VirtualBox).
78
star
5

spring-schema-registry

The purpose of this module is to solve the problem of multiple keystores using Spring Boot + Kafka + Schema Registry + SSL and Spring Schema Resgistry Test
Java
28
star
6

java-fluent-validator-predicates

Java Fluent Validator is inspired by Fluent Interface and .Net FluentValidation allowing Java and Kotlin developers write validations in a fluent and performatic way. Predicates are the base for the project and make even easier to build your validators. You will find some built-in predicates in this project that will speed up your development.
Java
9
star
7

aws-gen-cli

awsgen is the software that manage AWS Security Token Service (STS) and enables you to request temporary, limited-privilege credentials for AWS Identity and Access Management (IAM) users or for users that you authenticate (federated users).
Python
8
star
8

javascript-collections

JavaScript implementation of different collections
JavaScript
5
star
9

amazon-sns-java-messaging-lib

Robust SNS Client Producer. The Amazon SNS Java Messaging Library holds the compatible classes, that are used for communicating with Amazon Simple Notification Service.
Java
5
star
10

gluster-simple-csi-driver

Gluster Container Storage Interface (CSI) driver
Go
4
star
11

jnlp-slave-dotnet-framework

Jenkins JNLP Slaves as Windows Container
Dockerfile
2
star
12

spring-camel-kafka-schema-registry

How to integrate Spring-Boot + Camel + Kafka + Schema Registry
Java
2
star
13

spring-cassandra-embedded

The purpose of this application is to start an instance of Cassandra quickly and to assist in the development (local) of applications that make use of Cassandra. Remember development!
Java
2
star
14

transforming-responses

Transforming responses wiremock
Java
1
star
15

bamboo-agent-azure

Bamboo agent and tools
Dockerfile
1
star
16

cucumber-rest-assured-junit

Java
1
star
17

gluster-debian

GlusterFS containers namely server. GlusterFS Docker image a non systemd distribution.
Shell
1
star
18

java-jna-example

This chapter will show you how to use JAVA JNA.
Java
1
star