edwardmlyte
edwardmlyte

Reputation: 16607

Unable to pick up custom camel converter

I've created a new converter with the following structure:

package com.mycompany;

@Converter
public final class MyCustomConverter {
  @Converter
  public static TypeB convert(TypeA typeA) {
  // do the conversion
  }
}

I've also created in my src/main/java/resources folder the following package, META-INF.services.org.apache.camel and within that a TypeConverter file which just says:

com.mycompany

Within my route from TypeA I have got:

<convertBodyTo type="com.mycompany.TypeB" />

Yet my tests constantly fail to pick up the file and thus cannot find the converter, with the exception being:

Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: com.mycompany.TypeA to the required type: com.mycompany.TypeB with value TypeA[value1="blah"]

Am I meant to do something else to get my test to pick up the TypeConverter file? Surely putting it in that resources folder with the exact structure adds it to the classpath and so it would be accessible.

Upvotes: 1

Views: 4549

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55540

Its recommended in the TypeConverter file to list the FQN of all the type conveters, eg

com.mycompany

Should be

com.mycompany.MyCustomConverter

This is also what we say on this page: http://camel.apache.org/type-converter.html

And could you check inside the generated JAR file of yours, that the META-INF/services/org/apache/camel directory is there, and that the TypeConverter file is present (and it is not in some directory like META-INF/org.apache.camel).

Also what is the runtime environment you use? Do you run Camel standalone, Tomcat, OSGi or something else?

Upvotes: 3

Related Questions