我正在尝试使用 camel-bindy 将 POJO 编组为 CSV,使用以下设置:
<bean id="bindyDataFormat" class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat">
<constructor-arg value="com.foo.kod.domain" />
<camel:route>
<camel:from uri="ref:kod.handler.list.in.csv" />
<camel:choice>
<camel:when>
<camel:xpath>$Accept = 'application/json' </camel:xpath>
<camel:to uri="bean:handlerListProcessor?method=process" />
<camel:marshal ref="myJSON" />
</camel:when>
<camel:when>
<camel:xpath>$Accept = 'text/csv' </camel:xpath>
<camel:to uri="bean:handlerListProcessor?method=process" />
<camel:marshal ref="bindyDataformat">
<camel:bindy type="Csv" packages="com.foo.kod.domain"/>
</camel:marshal>
</camel:when>
<camel:otherwise>
<camel:to uri="bean:handlerListProcessor?method=process" />
<camel:marshal ref="myJSON" />
</camel:otherwise>
</camel:choice>
</camel:route>
但这每次都会抛出 ClassCastException :
java.lang.ClassCastException: com.foo.kod.domain.Handler cannot be cast to java.util.Map
at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.marshal(BindyCsvDataFormat.java:93)
at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:58)
at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)
at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:99)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)
at org.apache.camel.fabric.FabricTraceProcessor.process(FabricTraceProcessor.java:81)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)