Hi Mark,

Camel picks the most suitable @Converter by traversing the chain of
inheritance, comparing the actual payload type against the available
@Converters.

The unit tests of the components deal with Strings and with Objects, so in
theory everything should work.

What may be happening is that your String is actually a Stream, in which
case I can definitely see an issue cropping up, because the Stream will
fall into the generic type of "Object".

You can display the current payload type just before sending to the MongoDB
endpoint by using a Log endpoint with showBodyType=true.

If it's a Stream, then you can do a <convertBodyTo type="String" /> before
the MongoDB endpoint to ensure it gets recognised.

Anyway, sure, we can make this @Converter a @Fallback converter and do
something more intelligent. But that intelligence comes at the cost of
performance, and converters are neat but can be nasty if they take a long
time to run.

Despite that I think we have a cache in place so maybe the intelligence is
only applied once, although I don't know if this is true for @Fallback
converters too. Will have to check.

Regards,

*Raúl Kripalani*
Apache Camel Committer
Enterprise Architect, Program Manager, Open Source Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk <http://twitter.com/raulvk>

On Tue, Oct 9, 2012 at 3:11 PM, Mark Doyle <markjohndo...@gmail.com> wrote:

> Hi all,
>
> Camel-mongodb has a set of provided type converters.
>
> @Converter
> public static DBObject fromStringToDBObject(String s) {
> ..blah blah
> }
>
> @Converter
> public static DBObject fromAnyObjectToDBObject(Object value) {
> ...blah blah
> }
>
>
> I'm trying to run a query which means sending a json string. After some
> debugging it looks like Camel selects the fromAnyObjectToDBObject converter
> rather than the fromStringToDBObject converter. I''m not sure of the
> consequences of this yet, with regards to the the mongodb component, but it
> did raise the question on how Camel deals with converters that could
> overlap given inheritance, a String is an Object after all.
>

Reply via email to