Skip to content

Israiloff/rjvalidation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central

Reactive Java Validation plugin.

This plugin has been created to simplify using Java Validation Api in the reactive java world.

Annotations

For those who are interested in "Cm" prefix in these annotations means "customized"

All code samples uses annotations from Project Lombok to simplify code structure.

A String type element annotated with this annotation must not be null and must contain at least one non-whitespace character.

import com.github.israiloff.rjvalidation.CmNotBlank;

@Data
@AllArgsConstructor
class Foo {

    /**
     * This field must not be null and must contain at least one non-whitespace character.
     */
    @CmNotBlank
    private String text;

} 

A Collection type element annotated with this annotation must not be null nor empty.

import com.github.israiloff.rjvalidation.CmNotEmpty;

@AllArgsConstructor
class Foo {

    /**
     * This field must not be null nor empty.
     */
    @CmNotEmpty
    private List<Object> objects;
}

Any element annotated with this annotation must not be null.

import com.github.israiloff.rjvalidation.CmNotNull;

@AllArgsConstructor
class Foo {

    /**
     * This field must not be null.
     */
    @CmNotNull
    private Object object;
}

A String type element annotated with this annotation must match to the specified regular expression (regex) or must be null.

import com.github.israiloff.rjvalidation.CmPattern;

@Data
@AllArgsConstructor
class Foo {

    /**
     * This field must match to the specified regular expression (regex) or must be null.
     */
    @CmPattern(regexp = "^\\w+$")
    private String text;

} 

A String type element size annotated with this annotation must be between the specified boundaries (included).

import com.github.israiloff.rjvalidation.CmSize;

@Data
@AllArgsConstructor
class Foo {

    /**
     * This field's size must be between 2 and 10 chars (boundaries included) 
     */
    @CmSize(min = 2, max = 10)
    private String text;

} 

A full sample of usage in Spring Boot Application.

Model

import com.github.israiloff.rjvalidation.CmNotBlank;
import com.github.israiloff.rjvalidation.CmNotEmpty;
import com.github.israiloff.rjvalidation.CmNotNull;
import com.github.israiloff.rjvalidation.CmPattern;
import com.github.israiloff.rjvalidation.CmSize;

@Data
@AllArgsConstructor
class Foo {

    @CmNotBlank
    private String notBlankField;

    @CmNotEmpty
    private List<Object> notEmptyField;

    @CmNotNull
    private Object notNullField;

    @CmPattern(regexp = "^\\w+$")
    private String regexMatchField;

    @CmSize(min = 1, max = 20)
    private String text;

}

Usage

@Component
@Validated
class Context {
    public void usage(@Valid Foo foo) {
        System.out.println(foo);
    }
}