Verifier

Verifier is a Java library for validation.

License

License

Categories

Categories

Ninja User Interface Web Frameworks
GroupId

GroupId

org.notninja
ArtifactId

ArtifactId

verifier
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

Verifier
Verifier is a Java library for validation.
Project URL

Project URL

https://github.com/NotNinja/verifier
Source Code Management

Source Code Management

https://github.com/NotNinja/verifier

Download verifier

How to add to project

<!-- https://jarcasting.com/artifacts/org.notninja/verifier/ -->
<dependency>
    <groupId>org.notninja</groupId>
    <artifactId>verifier</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.notninja/verifier/
implementation 'org.notninja:verifier:0.3.0'
// https://jarcasting.com/artifacts/org.notninja/verifier/
implementation ("org.notninja:verifier:0.3.0")
'org.notninja:verifier:jar:0.3.0'
<dependency org="org.notninja" name="verifier" rev="0.3.0">
  <artifact name="verifier" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.notninja', module='verifier', version='0.3.0')
)
libraryDependencies += "org.notninja" % "verifier" % "0.3.0"
[org.notninja/verifier "0.3.0"]

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19

Project Modules

There are no modules declared in this project.

Verifier

Verifier is a Java library for validation which concentrates on providing a simple API with useful (and readable!) error messages, all while being highly configurable so that it's useful in your application code.

Build Coverage Translations JavaDoc License Maven Central

Install

To install Verifier, simply add it as a dependency to your project:

Maven:

<dependency>
    <groupId>org.notninja</groupId>
    <artifactId>verifier</artifactId>
    <version>0.3.0</version>
</dependency>

Gradle:

compile 'org.notninja:verifier:0.3.0'

That's it! You'll need to have Java 8 or above though.

API

Verifier offers validation methods for a lot of standard Java data types:

package com.example.form;

import org.notninja.verifier.Verifier;

public class LoginForm implements Form {

    UserService userService;

    @Override
    public void handle(Map<String, String> data) {
        Verifier.verify(data)
            .containAllKeys("username", "password");
            .and(data.get("username"), "username")
                .not().blank();
            .and(data.get("password"), "password")
                .not().empty()
                .alphanumeric();

        userService.login(data);
    }
}

However, you can also provide implementations of CustomVerifier to support more specific use cases instead of just data types.

package com.example.form;

import com.example.verifier.PasswordVerifier;

import org.notninja.verifier.Verifier;

public class RegistrationForm implements Form {

    UserService userService;

    @Override
    public void handle(Map<String, String> data) {
        Verifier.verify(data)
            .containAllKeys("username", "password");
            .and(data.get("username"), "username")
                .not().blank()
                .that((value) -> userService.isAvailable(value));
            .and(data.get("password"), "password", PasswordVerifier.class)
                .not().nulled()
                .strong();

        userService.register(data);
    }
}

The best way to learn about the API is to simply use it and explore. It's designed to be very natural and simple. Each verification method is documented with examples to help explain exactly what's being verified.

Here's a list of the data types supported by Verifier already:

  • Array
  • BigDecimal
  • BigInteger
  • Boolean
  • Byte
  • Calendar
  • Character
  • Class
  • Collection
  • Comparable
  • Date
  • Double
  • Float
  • Integer
  • Locale
  • Long
  • Map
  • Object
  • Short
  • String
  • Throwable

If a data type is missing that you'd like to see supported by Verifier, please take a look at the Contributors section below.

Bugs

If you have any problems with Verifier or would like to see changes currently in development you can do so here.

Contributors

If you want to contribute, you're a legend! Information on how you can do so can be found in CONTRIBUTING.md. We want your suggestions and pull requests!

A list of Verifier contributors can be found inAUTHORS.md.

License

See LICENSE.md for more information on our MIT license.

Copyright !ninja

org.notninja

!ninja

There are no ninjas here!

Versions

Version
0.3.0