Hi,
I am looking at feasibility of using Spring 3.1.0 validation framework to implement validation to all the API's that I have developed. In the service implementation layer, I need to add the validation to each of the service/functions in order to check if the passed params are valid and have correct values. What I found from initial investigation is that Spring's Validator Interface has to be implemented for each POJO's that I have.
- But it may happen that for the given service, as in my case, that during validation one POJO's property value's validity may depend on another passed POJO's property value. So basically, service's POJO param's are valid or not, It can be interdependent.
- Also, one POJO may have different validation logic in different services. May be I can allow one of it's property to be null in one case and not null in another cased for different services.
Is there any way to use Spring Validation framework in this case. If yes, how? If not, Please share if you have any other framework idea which will fit in my case.
The Validator gets passed an Object, not a specific domain object. Which means you can create an object that holds both domain objects if the validation is about values from those two objects, then write your validator.
You can just create a wrapper object that holds onto both domain objects. Or if one of the domain objects already holds a reference to the other domain object, then pass the one domain object.
Think just Java, There are always solutions. You can also choose to use JSR 303 and @Valid if you want.