Skip to content

Textile86/java-project-78

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Hexlet tests and linter status:

Actions Status

Java CI

Quality Gate Status

Валидатор данных

Java-библиотека для валидации данных

Возможности

  • Валидация строк, чисел, Map
  • Цепочка вызовов
  • Вложенная валидация структур данных

Использование

Validator v = new Validator();

Валидация строк

StringSchema schema = v.string()
    .required()
    .minLength(5)
    .contains("hello");

schema.isValid("hello world"); // true
schema.isValid("hi");          // false
schema.isValid(null);          // false

Валидация чисел

NumberSchema schema = v.number()
    .required()
    .positive()
    .range(1, 100);

schema.isValid(50);   // true
schema.isValid(0);    // false
schema.isValid(null); // false

Валидация Map с структурой

Map<String, BaseSchema> schemas = new HashMap<>();
schemas.put("name", v.string().required());
schemas.put("age", v.number().positive());

MapSchema schema = v.map()
    .required()
    .sizeof(2)
    .shape(schemas);

Map<String, Object> person = Map.of("name", "John", "age", 25);
schema.isValid(person); // true

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages