ConversionService detects generic type declaration on target class behind proxy as well

Issue: SPR-14822
This commit is contained in:
Juergen Hoeller
2016-10-21 12:24:12 +02:00
parent 52b029d71d
commit f7d740fa69
5 changed files with 129 additions and 41 deletions

View File

@@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.DecoratingProxy;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
@@ -97,9 +98,13 @@ public class FormattingConversionService extends GenericConversionService
static Class<?> getFieldType(Formatter<?> formatter) {
Class<?> fieldType = GenericTypeResolver.resolveTypeArgument(formatter.getClass(), Formatter.class);
if (fieldType == null && formatter instanceof DecoratingProxy) {
fieldType = GenericTypeResolver.resolveTypeArgument(
((DecoratingProxy) formatter).getDecoratedClass(), Formatter.class);
}
if (fieldType == null) {
throw new IllegalArgumentException("Unable to extract parameterized field type argument from Formatter [" +
formatter.getClass().getName() + "]; does the formatter parameterize the <T> generic type?");
throw new IllegalArgumentException("Unable to extract the parameterized field type from Formatter [" +
formatter.getClass().getName() + "]; does the class parameterize the <T> generic type?");
}
return fieldType;
}