spring-projects/spring-data-commons

Consider SpEL-templated annotations

Opened this issue · 1 comments

When considering the following annotation:

@RangeEncrypted(contentionFactor = 0L,
        rangeOptions = "{\"min\": {\"$numberDouble\": \"0.3\"}, \"max\": {\"$numberDouble\": \"2.5\"}, \"precision\": 2 }")

the rangeOptions attribute contains a JSON-like string consisting of a specific syntax and values (0.3, 2.5). Using composed annotations, building higher-level blocks on top of an annotation always requires the exact annotation attribute value in which values and structure are static. Such an approach would render meta-annotations that have fixed values.

It would be however much nicer to allow composed annotations containing placeholder references in a string and providing values for placeholders through the actual composed annotation. Something along the lines of:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@RangeEncrypted(contentionFactor = 0L,
        rangeOptions = "{\"min\": {\"$numberDouble\": \"#{#this.min}\"}, \"max\": {\"$numberDouble\": \"#{#this.max}\"}, \"precision\": 2 }")

public @interface RangeEncryptedDouble {


    @PlaceholderValue String min();

    @PlaceholderValue String max();
}


@RangeEncryptedDouble(min="0.3", max="2.5")

Using @PlaceholderValue as indicator for selective placeholder value demarcation. MergedAnnotation.getMetaSource() could be used as source for the meta-annotation to get hold of the parameters and on the evaluation-side, we could introduce evaluation, where necessary.

Sounds like a request for core FW.