【发布时间】:2017-06-15 22:35:50
【问题描述】:
我正在使用一个应该与
匹配的 ConditionalConverter@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return sourceType.hasAnnotation(Document.class);
}
但在这里,sourceType.hasAnnotation(Document.class) 会返回 false,即使提供的类是例如:
@Document
class Person {}
如果我看看后面是什么,从 Class 创建 TypeDescriptor 没有注意注释:
public static TypeDescriptor valueOf(Class<?> type) {
if (type == null) {
type = Object.class;
}
TypeDescriptor desc = commonTypesCache.get(type);
return (desc != null ? desc : new TypeDescriptor(ResolvableType.forClass(type), null, null));
}
有关更多信息,对转换器的调用是通过 org.springframework.core.convert.ConversionService.canConvert(Class sourceType, Class targetType)
来自 Spring 的代码来自 4.2.8.RELEASE
不知道如何让我的转换器工作。
【问题讨论】: