名前で注釈を付ける必要があるクラスがほとんどないため、注釈を次のように定義しました
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface JsonUnmarshallable {
public String value();
}
この注釈が必要なクラスは次のように定義されます。
@JsonUnmarshallable("myClass")
public class MyClassInfo {
<few properties>
}
以下のコードを使用して注釈をスキャンしました
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);
}
問題は、返されたマップに含まれていることですが、キーとして["myClassInfo" -> object of MyClassInfo]
マップを含める必要があり"myClass"
ます。これは、Bean 名ではなく注釈の値です。
これを行う方法はありますか?