I currently am trying to proxy some existing JAX/RS resources, in order to allow me to use the Hibernate Validator\'s method validation support. However, when I proxy my class (
CGLib Enhancer technically is just extending from your Class. I do not know if this is feasible for you (number of objects) but how about exposing an interface instead of the class?
Object p2 = Enhancer.create(resource.getClass(),
new Class[] { IResource.class },
new MethodInterceptor() {
public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3)
throws Throwable {
return arg3.invokeSuper(arg0, arg2);
}
});
Remove the annotations from the enhanced class and put them into the interface. Validate then against the interface. This might be a lot of boiler-plate interfaces for many such resources, but still seams a lot better than mapping everything to form backing objects or DTOs.