项目作者: bean-validation-scala

项目描述 :
JSR 303 and 349 Bean Validation for Scala.
高级语言: Scala
项目地址: git://github.com/bean-validation-scala/bean-validation-scala.git
创建时间: 2015-02-11T08:04:58Z
项目社区:https://github.com/bean-validation-scala/bean-validation-scala

开源协议:MIT License

下载


bean-validation-scala

JSR 303 and 349 Bean Validation for Scala.
This library enable validation to some Monad. (e.g. Option, Seq, etc)

Build Status
Maven Central
Scaladoc

Getting Started

Support Scala 2.11 and 2.12

  1. libraryDependencies ++= Seq(
  2. "com.tsukaby" %% "bean-validation-scala" % "0.4.2"
  3. )

This library has been published in the Maven central.

How to use

Step 1. Add annotations to your case class.

  1. import javax.validation.constraints.Size
  2. case class Person(
  3. @(Size@field)(min = 4)
  4. name: Option[String]
  5. )

Step 2. Create validator by our library.

  1. import com.tsukaby.bean_validation_scala.ScalaValidatorFactory
  2. val validator = ScalaValidatorFactory.validator

Step 3. Validate a case class object.

  1. val obj = Person(Some("abc"))
  2. val violations = validator.validate(obj)
  3. if (violations.nonEmpty) {
  4. println("Violations found!")
  5. }

Other information.

Support annotations.

javax.validation.constraints

  • AssertFalse
  • AssertTrue
  • DecimalMax
  • DecimalMin
  • Digits
  • Future
  • Max
  • Min
  • Past
  • Pattern
  • Size

org.hibernate.validator.constraints

  • CreditCardNumber
  • EAN
  • Email
  • Length
  • LuhnCheck
  • Mod10Check
  • Mod11Check
  • NotBlank
  • NotEmpty
  • Range
  • SafeHtml
  • URL

com.tsukaby.bean_validation_scala

Original annotations.

  • AssertNone
  • AssertSome
  • ByteSize

Doesn’t support annotations.

  • NotNull // What do you think I should do?
  • Null
  • ModCheck // Deprecated
  • ParameterScriptAssert
  • ScriptAssert

Contribution

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.

License

  1. Copyright 2015 - 2017 tsukaby.com
  2. MIT License