Java Object Validator

Validate object structure and values by utilizing the java compiler for type checking

License

License

GroupId

GroupId

com.github.ingarabr
ArtifactId

ArtifactId

validation
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Java Object Validator
Validate object structure and values by utilizing the java compiler for type checking
Project URL

Project URL

https://github.com/ingarabr/java-object-validator
Source Code Management

Source Code Management

https://github.com/ingarabr/java-object-validator/tree/master

Download validation

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
cglib : cglib-nodep jar 3.2.4

test (2)

Group / Artifact Type Version
com.google.guava : guava jar 19.0
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

Validation

This is a library used to validate java object against a set of validation rules.

This is inspired by mockito and hamcrest so it should be familiar to use if you know those tools.

Limitations

It requires that the objects follow the java bean convention with a field and a getter is present.

How to use

build the project and import it with maven.

<dependency>
  <groupId>com.github.ingarabr.validator</groupId>
  <artifactId>validation</artifactId>
  <version>{validation.version}</version>
</dependency>

Building up a rule

First we need to specify the field we need:

field(SomeBean.class).getValue();

Now we can add a validation condition to it:

validation(field(SomeBean.class).getValue(), mustHaveValue());

This can be chain into other validation conditions like and, or etc.

To verify that an object is valid against the validation condition the API expose two method. isValidateObject that gives a boolean result and validateObject that gives a set of violations. The set it empty if no validation condition is violated.

Validation validation = validation(field(SomeBean.class).getValue(), hasOneOfTheValues("foo1", "foo2"));
boolean isValid = fieldCondition.isValidateObject(new SomeBean().value("foo1"));

See the test for more example of usage.

Versions

Version
1.0.0