Validate Your Microservices With MicroProfile and Bean Validation

Can someone validate these for me?

Is a common code practice in our microservices to have a lot of If’s blocks to validate if some values are null, or if they have the right size, the dates are correct, etc. then the developer needs to inform the user that something went wrong and 50% of our code are those validations.

Fortunately, within the JavaEE/JakartaEE API’s there is Bean Validation that allows the developer to reduce all of that validation code in a declarative way using annotations and can be used along with MicroProfile to write better microservices that not only informs the users that something went wrong but also let them know how to fix it.

Data Integrity in NoSQL and Java Applications Using Bean Validation

The NoSQL databases are famous because they are schemaless. That means a developer does need to care about a pre-defined type as it does on a relational database; thus, it makes it easier for developers to create an application. However, it has a considerable price once there is no structure that is not trivial to validate it on the database. To ensure integrity, the solution should work on the server side. There is a specification and framework in the Java world that is smoother and annotation-driven: bean validation. This post will cover how to integrate bean validation in a NoSQL database.

Bean Validation, JSR 380, is a specification which ensures that the properties of a Class match specific criteria, using annotations such as @NotNull, @Min, and @Max, also create its annotation and validation. It is worth noting bean validation does not, necessarily, mean an anemic model; in other words, a developer can use it with good practices to get data integrity.