I'm implementing an API gateway in Java, where the request object has lots of fields and subobjects. There are numerous properties that are required
(should not be null) and some that are optional.
The code runs in Karaf and is using Blueprint, so some Spring-based mechanisms are possible, but we're not using much from Spring right now (although I'm familiar with the various Spring frameworks).
I'm aware of the Eclipse @NonNull
annotation, and I can add that annotation to getter methods that need to return a non-null value.
What I'd like to be able to do is run a reusable method on the request object that will determine if there are any constraint violations and return a human-readable error message (or something else).
There seem to be various ways to do this, but I'm not sure what framework strategy makes sense in my situation. For instance, there is commons-validator
, but that seems like it's specific to web page forms. I also saw some documentation for a hibernate validator
, but that seems like it wouldn't apply here.