Skip to content

Consider SpEL-templated annotations #3324

@mp911de

Description

@mp911de

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\": \"0.3\"}, \"max\": {\"$numberDouble\": \"2.5\"}, \"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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions