spring-projects / spring-projects/spring-data-commons
Consider SpEL-templated annotations
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 838
- Forks
- 730
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files or tests; start by tracing MergedAnnotation.getMetaSource() and the annotation evaluation paths mentioned in the proposal. Determine how composed-annotation parameters such as min and max would supply placeholders to RangeEncrypted, and consider the scope of evaluation needed for the example to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100