19
19
import java .lang .annotation .Annotation ;
20
20
import java .lang .reflect .AnnotatedElement ;
21
21
import java .lang .reflect .Method ;
22
+ import java .util .Collections ;
22
23
import java .util .HashMap ;
23
24
import java .util .List ;
24
25
import java .util .Map ;
26
+ import java .util .Set ;
25
27
import java .util .function .Function ;
26
28
27
29
import org .springframework .core .annotation .AnnotationConfigurationException ;
28
30
import org .springframework .core .annotation .MergedAnnotation ;
29
31
import org .springframework .core .annotation .MergedAnnotations ;
30
32
import org .springframework .core .annotation .MergedAnnotations .SearchStrategy ;
31
33
import org .springframework .core .annotation .RepeatableContainers ;
34
+ import org .springframework .core .convert .TypeDescriptor ;
35
+ import org .springframework .core .convert .converter .GenericConverter ;
32
36
import org .springframework .core .convert .support .DefaultConversionService ;
33
37
import org .springframework .util .PropertyPlaceholderHelper ;
34
38
55
59
*/
56
60
final class AuthorizationAnnotationUtils {
57
61
62
+ private static final DefaultConversionService conversionService = new DefaultConversionService ();
63
+
64
+ static {
65
+ conversionService .addConverter (new ClassToStringConverter ());
66
+ }
67
+
58
68
static <A extends Annotation > Function <AnnotatedElement , A > withDefaults (Class <A > type ,
59
69
PrePostTemplateDefaults defaults ) {
60
70
Function <MergedAnnotation <A >, A > map = (mergedAnnotation ) -> {
@@ -69,8 +79,7 @@ static <A extends Annotation> Function<AnnotatedElement, A> withDefaults(Class<A
69
79
for (Map .Entry <String , Object > property : annotationProperties .entrySet ()) {
70
80
String key = property .getKey ();
71
81
Object value = property .getValue ();
72
- String asString = (value instanceof String ) ? (String ) value
73
- : DefaultConversionService .getSharedInstance ().convert (value , String .class );
82
+ String asString = (value instanceof String ) ? (String ) value : conversionService .convert (value , String .class );
74
83
stringProperties .put (key , asString );
75
84
}
76
85
AnnotatedElement annotatedElement = (AnnotatedElement ) mergedAnnotation .getSource ();
@@ -156,4 +165,19 @@ private AuthorizationAnnotationUtils() {
156
165
157
166
}
158
167
168
+ static class ClassToStringConverter implements GenericConverter {
169
+
170
+
171
+ @ Override
172
+ public Set <ConvertiblePair > getConvertibleTypes () {
173
+ return Collections .singleton (new ConvertiblePair (Class .class , String .class ));
174
+ }
175
+
176
+ @ Override
177
+ public Object convert (Object source , TypeDescriptor sourceType , TypeDescriptor targetType ) {
178
+ return (source != null ) ? source .toString () : null ;
179
+ }
180
+
181
+ }
182
+
159
183
}
0 commit comments