Search code examples
javaspringtype-conversionspring-3

Spring conversion service - from List<A> to List<B>


I have registered a custom conversion service in a Spring 3 application. It works well for POJOs but it does not work on Lists.

For example, I convert from String to Role and it works fine, but not for List<String> to List<Role>.

All kind of ClassCastExceptions fly in the application when trying to inject Lists, no matter what they contain. The Conversion service calls the convertor for List<String> to List<Role> for all.

This makes sense if you think about it. Type erasure is the culprit here and the convertion service actually sees List to List.

Is there a way to tell the conversion service to work with generics?

What other options do I have?


Solution

  • Ralph was correct, it works if you have a converter that converts from A To B.

    I didn't need a converter for List<A> to List<B>.