Giter Site home page Giter Site logo

israiloff / rjvalidation Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 91 KB

Non blocking validation for working with project reactor

Home Page: https://github.com/Israiloff/rjvalidation

License: MIT License

Java 100.00%
central java maven plugin reactor spring validate validation validator webflux

rjvalidation's Introduction

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);
    }
}

rjvalidation's People

Contributors

israiloff avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.