Description
Oliver Becker opened SPR-6297 and commented
The algorithm implemented in GenericFormatterRegistry.findConverterByClassPair(Class, Class) apparently goes up the superinterface and superclass hierarchy to find a proper converter for a given source type. However, since the DefaultConversionService registers an ObjectToStringConverter, this converter will be preferred over specialized converters for interfaces.
Consider the following situation: class X implements the interface I which in turn is a subinterface of J. There is a special converter for J-to-String.
The classQueue will be filled in this case with
- X
- I (from X.getInterfaces())
- Object (from X.getSuperclass())
- J (from I.getInterfaces())
Since Object appears before J the generic ObjectToStringConverter will be used here instead of the more specific converter for J.
A more appropriate algorithm should probably consider first all interfaces before using the superclasses. In any case the ObjectToStringConverter should always be the last converter to be used.
Affects: 3.0 RC1
Sub-tasks:
- Optimize GenericConversionService.findConverterForClassPair [SPR-6749] #11415 Optimize GenericConversionService.findConverterForClassPair
Issue Links:
- Review Converter resolution algorithm [SPR-6314] #10980 Review Converter resolution algorithm
Referenced from: commits 010e72c