0

I Just want to learn custom converter and ran into issue. Any help is much appreciated. Camel Version 2.17 and JBoss Fuse 6.3

@Converter
public class MyConvertor{

    public MyConvertor(){}

    @Converter
    public static String convertTo(Exchange exchange) {}

}

In My Spring DSL

<convertBodyTo charset="UTF-8" id="_convertBodyTo1" type="com.x.convertor.MyConvertor"/>

In META-INF/services/org/apache/camel/TypeConverter

com.x.convertor.MyConvertor

Error message :

 org.apache.camel.InvalidPayloadException: No body available of type: com.x.convertor.MyConvertor but has value: GenericFile[output.txt] of type: org.apache.camel.component.file.GenericFile on: output.txt. Caused by: No type converter available to convert from type: 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.camel.component.file.GenericFile to the required type: com.x.convertor.MyConvertor

1 Answers1

1

There are a couple of errors. The type attribute should be your target type (the type you want after conversion).

<convertBodyTo charset="UTF-8" id="_convertBodyTo1" type="java.lang.String"/>

Camel can do this conversion automatically. If you want to write a converter on your own, mind that converter method should have the expected input type as parameter, and not the Exchange (which can be an optional second parameter from Camel 2.16 onwards).
Class should be something like:

@Converter
public class MyConvertor{

    public MyConvertor(){}

    @Converter
    public static String convertTo(GenericFile body, Exchange exchange) {
        // The exchange parameter is optional
    }

}

See https://camel.apache.org/type-converter.html
If you want to read the content of a CSV file to transform it into a POJO, use Bindy component.

Alessandro Da Rugna
  • 4,571
  • 20
  • 40
  • 64
  • No Luck. Updated changes as below . Could you please help Converter public class MyConvertor { Converter public JSONObject convertTo(GenericFile file) throws JSONException, IOException { return jsonObject; } } – Sarada Chelluboyena May 28 '17 at 23:09