You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tim Dudgeon <td...@gmail.com> on 2015/03/09 15:22:57 UTC
TypeConverter with generics
I may be missing something obvious here, but I'm can't find a way to do
a type conversion that uses generics.
For instance, I want to do a conversion of an InputStream into a
Collection of Foo objects.
So my convert method might look like this:
@Converter
public List<Foo> convertToFoo(InputStream input, Exchange exch) {
// something that converts the input into List<Foo>
}
But to use this I can't specify a generic type, only a class name
(presumably because of erasures)
List<Foo> myFoos = camelContext.getTypeConverter().convertTo(List.class);
And this means that I can't have another conversion that converts to
List<Bar>.
The only workaround I can see is to create subclasses of List
class FooList extends List<Foo> { }
class BarList extends List<Bar> { }
A related topic is described here:
http://gafter.blogspot.co.uk/2006/12/super-type-tokens.html
Are there any better solutions to this?
Tim