2

I would like to define two different converters methods for Camel that would take the same Object class and return the same Object class.

@Converter
public static Exchange fromStreamSourceToExchangeList1(StreamSource ss)

@Converter
public static Exchange fromStreamSourceToExchange2(StreamSource ss)

The issue is when I try to call my converter I can't specify which one to be used, only the desired types:

from(starter).routeId(Feed).to(uri).convertBodyTo(StreamSource.class).convertBodyTo(Exchange.class).process(..)

How can I specify a converter using convertBodyTo?

user3221287
  • 337
  • 3
  • 12
  • Have you included your converter in the `META-INF/services/org/apache/camel/TypeConverter` file as explained [here](http://camel.apache.org/type-converter.html)? – Roman Vottner Jul 03 '18 at 20:27
  • The converter is included in the TypeConverter file, my TypeConverter file only contains one line with points to a package containing all of my converters. – user3221287 Jul 03 '18 at 20:47
  • @user3221287 [`transform().method(SomeClass.class, "someMethod")`](https://camel.apache.org/message-translator.html) is more suitable for this case. Difference is described in [this answer](https://stackoverflow.com/questions/14501119/which-camel-construct-is-suited-for-transforming) – Bedla Jul 03 '18 at 20:48

1 Answers1

3

Camel only supports 1 type converter per from -> to. So this is not supported. When Camel startup and it detects 2+ of the same type converters you get a WARN logging and the last override the oldest (I think that is the default behaviour, but you can re-configure what to do).

So in this case, then do NOT use type converters, but use bean method calls, and call the method with the conversion you want.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65