GenericConversionService finds wrong converter for partially unresolvable generic types #34298
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
If there are multiple converters for similar types, but with different generic type arguments that are partially unresolvable - then the generic type arguments are effectively ignored and as a result one might get a non-matching converter.
The issue can be demonstrated with this test:
As far as I understand this could be fixed by a small change in GenericConversionService.ConverterAdapter#matches to take the resolvable part into account even if the type is not completely unresolvable. I.e. if the resolvable part does not match, then this converter does not match.
The concrete use case I have is converting a
List<A>
toList<B>
whereB
is a generated protobuf class which has partially unresolvable generics due to this. Also, I cannot use a plainConverter<A,B>
because the converter needs access to the full source list to produce the target list - so I the natural solution is to have aConverter<List<A>, List<B>>
, but it does not work since I have multiple such converters with same source type and different target types.One possible workaround would be to wrap the Lists in distinct wrapper classes during conversion, but I think it would be better to just make
GenericConversionService
consider partially resolvable generics.The text was updated successfully, but these errors were encountered: