I have few classes that I need to annotate with a name so I defined my annotation as
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface JsonUnmarshallable {
public String value();
}
Now the class that needs this annotation is defined as
@JsonUnmarshallable("myClass")
public class MyClassInfo {
<few properties>
}
I used below code to scan the annotations
private <T> Map<String, T> scanForAnnotation(Class<JsonUnmarshallable> annotationType) {
GenericApplicationContext applicationContext = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(applicationContext, false);
scanner.addIncludeFilter(new AnnotationTypeFilter(annotationType));
scanner.scan("my");
applicationContext.refresh();
return (Map<String, T>) applicationContext.getBeansWithAnnotation(annotationType);
}
The problem is that the map returned contains ["myClassInfo" -> object of MyClassInfo]
but I need the map to contain "myClass"
as key, which is the value of the Annotation not the bean name.
Is there a way of doing this?