2

I'm using Oval to do validations, so we have code that looks like this:

   @NotNull(errorCode = "NumberInvalid")
   @NotNegative(errorCode = "NumberInvalid")
   @Range(errorCode = "NumberInvalid", min=1, max=10)
   protected Integer dollarAmount;

I want to be able to update the range dynamically if needed, say if we have a config file that changes every month or so, I want to be able to reflect those changes in the validation.

Is there a way I can do this with reflection so that I don't have to subclass every annotation in Oval?

Jason
  • 13,563
  • 15
  • 74
  • 125

3 Answers3

0

Though annotations looks cleaner with static codes :) but ...there is a way.. Did you tried using reflection ? can you post the approach . You can have a look at this

Manish Singh
  • 3,463
  • 22
  • 21
0

As far as I'm aware this is not possible. Assuming your annotation retention is set to RUNTIME (which it would have to be for the validation to work) then what you will effectively have is a proxy class that implements the annotation interface, you won't be able to amend the values through reflection.

StuPointerException
  • 7,117
  • 5
  • 29
  • 54
0

The purpose of reflection is to access class members (including setting fields), but it does not cover adding new members or modifying existing declarations. What you want is more similar to bytecode editing or code refactoring.

Javier
  • 12,100
  • 5
  • 46
  • 57