While building applications and services it is very important that we maintain data integrity especially if they are data centric. It is crucial to have control over the data that the application interacts with to ensure it behaves as expected. This can be done using validations.

Many times the data received may get corrupted before reaching the application or the user may provide wrong inputs. This will not create a problem if validations are applied as the application can return invalid requests and may ask the user to provide correct fields, but in absence of validations it is surely to cause problems at some instance, as it may process incorrect data and disrupt the flow.

Spring makes our lives easier by providing us with some build-in validations like

  • @NotNull
  • @NotBlank
  • @Size
  • @Min

But sometimes these are not enough. For eg when we need to validate a field which should only expect a 10 digit phone number. In cases like these we need to build our own custom validations.

In this blog we will have a look at how we can add custom validations with the help of an example.

#scala #spring custom validations #spring #spring custom

Spring Custom Validations
3.50 GEEK