This library provides a set of additional bean validation (JSR 349 formerly JSR 303) constraints and validators.
You find the constraints in the package
de.malkusch.validation.constraints
:
@Age
: The Date must be in the past and at least that years old.@Adult
: The Date must be at least 18 years old.@BIC
: The String must be a valid BIC (Business Identifier Code) address.@IBAN
: The String must be a valid IBAN (International Bank Account Number) address.@BitcoinAddress
: Validates a bitcoin address.@TLD
: The String is a Top Level Domain.@Domain
: The String has to be a Domain.@IPv4
: The String has to be an IPv4 address.@ContentType
: The SpringMultipartFile
must match a ContentType. You have to provide javax.mail for the matching.@Image
: The SpringMultipartFile
must be an image.@NotEmptyBlob
: TheBlob
must not be empty (but can be null).@Country
: The String has to be a well formed ISO-3166-1 alpha-2 country code.@EqualProperties
: The bean has properties with equal values (e.g. two identical passwords).@ISBN
: The String has to be an ISBN (International Standard Book Number).
Some constraints require further dependencies. If you want to use them you have to provide those dependencies:
de.malkusch.validation.constraints.upload.*
requiresorg.springframework.web
andjavax.mail.mail
.
de.malkusch.validation.validator.jsr349
extends some JSR-349 built-in constraints with validators for additional types:
SizeValidatorForMultipartFile
: Validates a@Size
constraint against a SpringMultipartFile
.PastValidatorFor…
: Validates a@Past
constraint againstjava.time
(JSR 310: Date and Time API) objects.FutureValidatorFor…
: Validates a@Future
constraint againstjava.time
(JSR 310: Date and Time API) objects.
If you want to use these validators you have to include the mapping
resource META-INF/validation/mapping.xml. This can be done by
preferably create the file META-INF/validation.xml
and add that mapping or you do it programmatically with Configuration.addMapping(java.io.InputStream)
:
<?xml version="1.0" encoding="UTF-8"?>
<validation-config
xmlns="https://jboss.org/xml/ns/javax/validation/configuration"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.1.xsd">
<constraint-mapping>META-INF/validation/mapping.xml</constraint-mapping>
</validation-config>
You find this package in Maven central:
<dependency>
<groupId>de.malkusch.validation</groupId>
<artifactId>validation</artifactId>
<version>0.3.0</version>
</dependency>