activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <>
Subject [CAMEL] Heads up - generic type conversion mechanism implemented
Date Thu, 29 Mar 2007 16:07:26 GMT
Its very common when routing from one endpoint to another to need to
convert the body payloads from one type to another such as to/from
objects of types


I've added a default implementation of the TypeConverter which is
capable of converting between types.  It works by searching the
classpath for files called:
META-INF/services/org/apache/camel/TypeConverter which the contents
are expected to be comma separated package names. These packages are
then recursively searched for any objects with the @Converter
annotation. Then any method marked with @Converter is assumed to be a
conversion method; where the parameter is the from value and the
return is the to value.

e.g. the following shows how to register a converter from File -> InputStream

public class IOConverter {

    public static InputStream toInputStream(File file) throws
FileNotFoundException {
        return new BufferedInputStream(new FileInputStream(file));

I think we've most of the common converters done. I've documented how
this all works in a little more detail here

Note this mechanism isn't a replacement for all transformers; custom
transformers can still be plugged into a pipeline. Its just to
automate away lots of the drudgery of turning byte[] into String or
Document or Source etc.


View raw message