简体   繁体   中英

type conversion in apache camel

I am pretty new to Apache Camel and currently I am making a test project. Currently I am trying to write some previously processed objects from custom class into a file using the file component (i dont know a better option).

from("direct:processedDecimals")
            .to("file:data/output")

but i have the following problem

   Caused by: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: Add{x=5.63, y=78.016} of type: org.example.math.Add on: Message[ID-NTB828-1537281187742-0-10]. Caused by: No type converter available to convert from type: org.example.math.Add to the required type: java.io.InputStream with value Add{x=5.63, y=78.016}. Exchange[ID-NTB828-1537281187742-0-9]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.example.math.Add to the required type: java.io.InputStream with value Add{x=5.63, y=78.016}]

I saw on the internet that some people suggests writing custom TypeConverter and then register it in a file in the WEB-INF folder. But I am using SpringBoot and its internal Tomcat and I dont have this directory.

You can convert body to String with convertBodyTo(String.class) , it will use toString method on Your object to make a conversion:

from("direct:processedDecimals")
    .convertBodyTo(String.class)
    .to("file:data/output");

This should write 'Add{x=5.63, y=78.016}' into the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM