user3221287
user3221287

Reputation: 357

Apache Camel - Specify which converter to use

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?

Upvotes: 2

Views: 1410

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55540

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.

Upvotes: 3

Related Questions