Java Object Validator

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

Лицензия

Лицензия

Группа

Группа

com.github.ingarabr
Идентификатор

Идентификатор

validation
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Java Object Validator
Validate object structure and values by utilizing the java compiler for type checking
Ссылка на сайт

Ссылка на сайт

https://github.com/ingarabr/java-object-validator
Система контроля версий

Система контроля версий

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

Скачать validation

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
cglib : cglib-nodep jar 3.2.4

test (2)

Идентификатор библиотеки Тип Версия
com.google.guava : guava jar 19.0
junit : junit jar 4.11

Модули Проекта

Данный проект не имеет модулей.

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.

Версии библиотеки

Версия
1.0.0