Bypass getter validation for seemingly getters

Hi all,

we are using Jersey 2.28 with Hibernate Validator 6.0.15. We have classes (REST resources) providing data via methods called “get*”. Some of these methods do not have any explicit parameters but retrieve them indirectly from the HTTP header. So they just seem like bean properties but are not.

Jersey processes a REST call as follows:

  1. Validating input parameters via Hibernate Validator.
  2. Calling the method.
  3. Validating the result via Hibernate Validator.

If some header data is missing for a seemingly getter, it will throw an appropriate exception. If this happens in step 2, everything is fine. But since Hibernate Validator treats the getter as bean property (ConstrainedExecutable.isGetterMethod() is true), it validates the result in step 1. Therefore validation fails with a validation exception wrapping/swallowing the actual exception for missing header data.

Is it possible to disable the behaviour to treat all “get*” methods without parameters as bean property in Hibernate Validator? I do not want to rename these methods. They return data, so “getData” is an appropriate name.

I tried to implement a bypass for Hibernate Validator but failed due to classes (e. g. MethodConstraintMappingContextImpl) and methods (e. g. BeanMetaDataManager.createBeanMetaData(Class)) not being extensible and wrapping being prevented by using implementations instead of interfaces (e. g. ConfigurationImpl.addMapping(ConstraintMapping)).