-5

I'm trying to invoke this method:

public Response getWithPathParam(@ApiParam( 
        value = "Service group to check",
        allowableValues = ApiConstants.components,                                                   
        required = true )

but want that allowableValues attribute will get a value that can be varying.

what I mean that I assuming allowableValues is a String.

I wondering if there is a way of reading a string from configuration and pass it into the attributes.

my attempt so far just led into the error of:

"Attribute value must be constant"

can you help please?

roman
  • 23
  • 4

2 Answers2

1

Generally, compiler errors cannot be handled in any way other than fixing them. It is only runtime errors that can somehow be handled.

According to the java language specification, a parameter to an annotation must be a compile-time constant.

This means that you cannot do anything even remotely close to what you are trying to do.

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
0

Java prevents to accept any other annotation parameter other than a constant, so you need to change ApiConstants.components to be a fixed value, for example:

  class ApiConstants{
     public static final String[] CONSTANTS = {"VAL_1","VAL_2"};
  }

If you still want to stay with dynamic configuration, then you need to handle it within the method itself.

Beri
  • 11,470
  • 4
  • 35
  • 57