...
At present the common parameter handling and validation comprises of multiple classes and interfaces and perform cross field validation. The current implementation of bean validation is quite flexible as it has its own annotation interface declarations that allow for custom constraints logic as illustrated in the image below.
Although Spring validation and java x validation offer their own annotations and error handling, it is believed that the validation checking that these constraint annotations enforce does not at times provide the same level of validation that the current common provides which, may have a work around that will involve utilizing self-defined annotation and validation classes like the one shown in the figure above along with the API defined annotations.
...
Incorporating the javax bean validation API aka JSR-380 or JSR-303 into the current common in my opinion can be achieved for the most part. Spring boot validation along with custom annotations would be required in order to ensure that the correct level of constraint has been achieved, if replicating current validation is necessary. Specific constraints and validation rules can be crafted for handling common parameters using the java validation API if required or one can do class level two step authentication as seen below.
This level of validation uses the validated annotation from the spring validation library and provides pre validation on parameters being sent to the class or application. The second level of validation is provided by the java x valid annotation. This will ensure that the object on which it is called satisfy the constraint, whether that be its data type, content, length and so on. Utilization of the libraries like this is suitable for restructuring at class level for components like participants or runtime parameter handling but do not provide a common parameter handling solution. To achieve this I believe that, depending on the needs of the project or design decisions it can be achieved using the following methods.
- Decide on what library is best suited for the job, in my opinion the spring boot starter validator or hibernate validator will work but I do not know the memory implications that come with each at initial run.
- The next step will be to create the annotation interfaces that will define the class that will validate the constraint whenever the annotation is used.
- Next, validation logic must be created for the annotation and this will be a custom constraint that can be reused throughout the project.
- Once we have enough custom validators we need to focus on bean validation which can prove to be tricky to accomplish seeing as a validation class cannot be created to validate every bean when desired.
...