LIVR javax validator parent

Language Independent Validation Rules (v2.0) - javax annotation validator parent

License

License

GroupId

GroupId

com.github.gaborkolarovics
ArtifactId

ArtifactId

livr-validator-parent
Last Version

Last Version

1.5.1
Release Date

Release Date

Type

Type

pom
Description

Description

LIVR javax validator parent
Language Independent Validation Rules (v2.0) - javax annotation validator parent
Project URL

Project URL

https://github.com/gaborkolarovics/livr-validator
Source Code Management

Source Code Management

https://github.com/gaborkolarovics/livr-validator/tree/master

Download livr-validator-parent

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.gaborkolarovics/livr-validator-parent/ -->
<dependency>
    <groupId>com.github.gaborkolarovics</groupId>
    <artifactId>livr-validator-parent</artifactId>
    <version>1.5.1</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.gaborkolarovics/livr-validator-parent/
implementation 'com.github.gaborkolarovics:livr-validator-parent:1.5.1'
// https://jarcasting.com/artifacts/com.github.gaborkolarovics/livr-validator-parent/
implementation ("com.github.gaborkolarovics:livr-validator-parent:1.5.1")
'com.github.gaborkolarovics:livr-validator-parent:pom:1.5.1'
<dependency org="com.github.gaborkolarovics" name="livr-validator-parent" rev="1.5.1">
  <artifact name="livr-validator-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.github.gaborkolarovics', module='livr-validator-parent', version='1.5.1')
)
libraryDependencies += "com.github.gaborkolarovics" % "livr-validator-parent" % "1.5.1"
[com.github.gaborkolarovics/livr-validator-parent "1.5.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • livr-core
  • livr-validator
  • livr-extra-rules

livr-validator

build Quality Gate Status Maven Central

Lightweight validator supporting Language Independent Validation Rules Specification (LIVR)

Description

See 'LIVR Specification' for detailed documentation and list of supported rules.

Features:

  • Rules are declarative and language independent
  • Any number of rules for each field
  • Return together errors for all fields
  • Excludes all fields that do not have validation rules described
  • Has possibility to validatate complex hierarchical structures
  • Easy to describe and undersand rules
  • Returns understandable error codes(not error messages)
  • Easy to add own rules
  • Rules are be able to change results output ("trim", "nested_object", for example)
  • Multipurpose (user input validation, configs validation, contracts programming etc)

Usage

Dependency

maven

<dependency>
  <groupId>com.github.gaborkolarovics</groupId>
  <artifactId>livr-validator</artifactId>
  <version>1.5.1</version>
</dependency>

Gradle

implementation 'com.github.gaborkolarovics:livr-validator:1.5.1'

Code

Schema source

  • Simple string schema
@LivrSchema(schema = "{\"name\": \"required\", \"email\": \"required\"}")
public class SamplePOJO{
    private String name;
    private String email;
    // Getter.. Setter..
}
  • Classpath resource
@LivrSchema(schema = "classpath:schemas/samplePOJO.json")
public class SamplePOJO{
    private String name;
    private String email;
    // Getter.. Setter..
}
  • File resource
@LivrSchema(schema = "file:/path/of/schemas/samplePOJO.json")
public class SamplePOJO{
    private String name;
    private String email;
    // Getter.. Setter..
}

Aliases

@LivrSchema(schema = "{\"password\": \"strong_password\"}"
    aliases = { "{\"name\": \"strong_password\", \"rules\": {\"min_length\": 6}, \"error\": \"WEAK_PASSWORD\"}" }
    )
public class SamplePOJO{
    private String password;
    // Getter.. Setter..
}

Alias loader support file: and classpath: resource loading like schema.

Custom rule

  • Pojo
@LivrSchema(schema = "{\"name\": {\"my_length\": 50 }}"
	rules = { MyLength.class })
public class SamplePOJO{
    private String name;
    private String email;
    // Getter.. Setter..
}
  • CustomRule
public class MyLength implements Rule {

    @Override
    public Function<List<Object>, Function<FunctionKeeper, Object>> func() {

        return ruleDefinition -> {
            final Long maxLength = Long.valueOf(ruleDefinition.get(0) + "");

            return wrapper -> {
                if ((wrapper.getValue() == null) || (wrapper.getValue() + "").equals("")) {
                    return "";
                }

                final String value = wrapper.getValue() + "";
                if (value.length() > maxLength) {
                    return "MY_TOO_LONG";
                }
                wrapper.getFieldResultArr().add(value);
                return "";
            };
        };
    }

    @Override
    public String rule() {
        return "my_length";
    }

}

Extra rules

This package contains livr-extra-rules module. See README.md.

@LivrSchema(schema = "{\"id\": \"uuid\" }}"
	scanRulePackages = { "livr.validation.rules" })

License

This repository is licensed under the GNU Affero General Public License.

Author

  • Java (LIVR 2.0), maintainer vlbaluk (Vladislav Baluk)
  • javax annotation, maintainer Gábor Kolárovics

Versions

Version
1.5.1
1.5.0
1.4.2
1.4.1
1.4.0
1.3.1
1.3.0
1.2.1