You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow a single element to override an array attribute in a meta-annotation [SPR-13972] #18544
In 4.2, aliased annotation attribute types must match exactly. However, it is rather common in Java for single element values to be specified for an array attribute: Reflecting this in custom annotation design, it would be nice for a custom annotation to be able to declare a single element only, aliasing a meta-annotation attribute which was originally declared as an array, e.g. in a custom @PropertySource variant with a single String value.
Deliverables
Allow for a single element overriding an array attribute in a meta-annotation by convention.
See findMergedAnnotationAttributesWithSingleElementOverridingAnArrayViaConvention() in AnnotatedElementUtilsTests.
Allow for a single element overriding an array attribute in a meta-annotation using @AliasFor.
See findMergedAnnotationAttributesWithSingleElementOverridingAnArrayViaAliasFor() in AnnotatedElementUtilsTests.
Ensure that the aforementioned overrides are supported in AnnotationAttributes (which is assumed to already be the case but should be verified).
See singleElementToSingleElementArrayConversionSupport() in AnnotationAttributesTests.
Ensure that the aforementioned overrides are supported in synthesized annotations.
See various getMergedAnnotation*WithSingleElementOverridingAnArrayVia*() and findMergedAnnotationWithSingleElementOverridingAnArrayVia*() methods in AnnotatedElementUtilsTests.
Juergen Hoeller, the committed change only works for reading such attributes via the AnnotationAttributes API -- actually, that (little known) feature has been in place for several years in AnnotationAttributes - however, this does not work for synthesized annotations.
When attempting to use this feature with synthesized annotations (e.g., a merged @RequestMapping), we see errors similar to the following (thrown from MapAnnotationAttributeExtractor.enrichAndValidateAttributes()):
java.lang.IllegalArgumentException: Attributes map {name=, value=/get, path=/get, params=[Ljava.lang.String;@6325a3ee, headers=[Ljava.lang.String;@1d16f93d, consumes=[Ljava.lang.String;@67b92f0a, produces=[Ljava.lang.String;@2b9627bc, method=[Lorg.springframework.web.bind.annotation.RequestMethod;@65e2dbf3} returned a value of type [java.lang.String] for attribute 'value', but a value of type [[Ljava.lang.String;] is required as defined by annotation type [org.springframework.web.bind.annotation.RequestMapping].
I have been planning on adding such support for synthesized annotations. So, do you want me to reopen/repurpose this issue or create a separate one to address this?
Activity
spring-projects-issues commentedon Feb 26, 2016
Sam Brannen commented
Juergen Hoeller, the committed change only works for reading such attributes via the
AnnotationAttributesAPI -- actually, that (little known) feature has been in place for several years inAnnotationAttributes- however, this does not work for synthesized annotations.When attempting to use this feature with synthesized annotations (e.g., a merged
@RequestMapping), we see errors similar to the following (thrown fromMapAnnotationAttributeExtractor.enrichAndValidateAttributes()):I have been planning on adding such support for synthesized annotations. So, do you want me to reopen/repurpose this issue or create a separate one to address this?
Cheers,
Sam
spring-projects-issues commentedon Feb 27, 2016
Juergen Hoeller commented
Let's reopen this one for the wider purpose in the 4.3 timeframe. I only really sneaked it in since I ran into it when coding a recent unit test :-)
Juergen
spring-projects-issues commentedon Feb 27, 2016
Sam Brannen commented
OK. I'm reopening this issue and assigning it to me in order to address annotations synthesized from maps.
spring-projects-issues commentedon Mar 6, 2016
Sam Brannen commented
Current work can be viewed in the following branch:
https://github.com/sbrannen/spring-framework/commits/SPR-13972
spring-projects-issues commentedon Mar 7, 2016
Sam Brannen commented
Pushed to
masterin the following commit:eb654dc