JSR 303 and 349 Bean Validation for Scala. This library enable validation to some Monad. (e.g. Option, Seq, etc)
libraryDependencies ++= Seq(
"com.tsukaby" %% "bean-validation-scala" % "0.4.0"
)
This library has been published in the Maven central.
Step 1. Add annotations to your case class.
import javax.validation.constraints.Size
case class Person(
@(Size@field)(min = 4)
name: Option[String]
)
Step 2. Create validator by our library.
import com.tsukaby.bean_validation_scala.ScalaValidatorFactory
val validator = ScalaValidatorFactory.validator
Step 3. Validate a case class object.
val obj = Person(Some("abc"))
val violations = validator.validate(obj)
if (violations.nonEmpty) {
println("Violations found!")
}
javax.validation.constraints
- AssertFalse
- AssertTrue
- DecimalMax
- DecimalMin
- Digits
- Future
- Max
- Min
- Past
- Pattern
- Size
org.hibernate.validator.constraints
- CreditCardNumber
- EAN
- Length
- LuhnCheck
- Mod10Check
- Mod11Check
- NotBlank
- NotEmpty
- Range
- SafeHtml
- URL
com.tsukaby.bean_validation_scala
Original annotations.
- AssertNone
- AssertSome
- ByteSize
- NotNull
// What do you think I should do?
- Null
- ModCheck
// Deprecated
- ParameterScriptAssert
- ScriptAssert
I'm seeking your PR!!! I'm easy.
For example.
- Bug fix
- Refactoring the code.
- Add a new feature, new annotations and others.
- Fix my odd English texts.
Copyright 2015 - 2015 tsukaby.com
MIT License