A Class Field Value Validation Library.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Kaptan Class Field Value Checker Build Status

"Kaptan" is a Turkish word that means captain.

Kaptan is a JAVA library that checks class fields in terms of input validation and verification. If it sees any variable violation, it immediately throws FieldViolationException.

Getting Started

How Can I Get It?


compile 'me.yesilyurt.burak:kaptan-field-checker:1.0.1'



How Can I Use It? Javadocs

Let's say that you have a model (POJO) class whose name is User and it has username and password String fields. Let's assume you don't want to get any null assignment for username field and empty value assignment for password field. You write an input validation mechanism on your own or you can use Kaptan for it. The below example shows a way to use Kaptan for it.

public class User {
    private String username;
    private String password;

Did you realise @MustBeNonNull and @MustBeNonEmpty annotations?

Those are annotations to help Kaptan to understand your intentations and the structure of your class. Since you put @MustBeNonNull above of your username field, Kaptan checks username field if it is null. If it sees null assignment in username field, it throws FieldViolationException to inform you.

Kaptan supports following annotations:

  • @MustBeNonNull
  • @MustBeNull
  • @MustBeNonEmpty
  • @MustBeEmpty
  • @EnforceSizeConstraint(min=, max=)
  • @EnforceRegexRule()
  • @EnforceIntervalConstraint(min=, max=)

To use Kaptan to check your classes' fields

You can initiliaze a KaptanFieldChecker object, then you should pass your model object into check function. Since it might throw FieldViolationException, you should write try&catch block and place KaptanFieldChecker in your try block. You can find an example below.

KaptanFieldChecker kaptanFieldChecker = new KaptanFieldChecker();
catch(FieldViolationException e){
    // You can place your exception handling codes.

What does Kaptan support?

Kaptan supports primitives, data structures that are in the Java collection library, and Strings. If you want to Kaptan support your custom data structure, you can make it happen by implementing KaptanField interface in your custom data structure.


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


This is an open-source project, we appreciate any contribution from contributors. If you want to improve Kaptan Class Field Input Checker, feel free to fork and create a pull request!

Support Me!


ETH: 0x47f4b805B2927fae671751ECe7D88d2638063bE9