JSON Validation Framework

Finatra provides a simple validation framework inspired by JSR-303.

The validations framework integrates Finatra’s custom case class deserializer to efficiently apply per field validations as request parsing is performed. The following validation annotations are available (and additional validations can be easily created):

  • @CountryCode
  • @FutureTime
  • @PastTime
  • @Pattern
  • @Max
  • @Min
  • @NotEmpty
  • @OneOf
  • @Range
  • @Size
  • @TimeGranularity
  • @UUID
  • @MethodValidation

Method Validations

A method validation is a case class method annotated with @MethodValidation which is intended to be used for validating fields of the cases class during request parsing. Reasons to use a method validation include:

  • For non-generic validations. @MethodValidation can be used instead of defining a reusable annotation and validator.
  • Cross-field validations (e.g. startDate before endDate)

For an example see the Car test case class. Additionally, see the CommonMethodValidations for pre-defined commonly useful method validations.

Validation Errors

By default validation errors are returned alphabetically sorted by validation error message (for determinism when testing). See the CaseClassMappingException.


  "errors" : [
    "location.lat: [9999.0] is not between -85 and 85",
    "location.long: field is required",
    "message: size [0] is not between 1 and 140",
    "nsfw: 'abc' is not a valid boolean"