我正在使用 Bindy 从以下 CSV 文件创建一个 Pojo,其中 side 是一个枚举:
orderId,symbol,side,price,quantity
1, MSFT, SELL, 19, 8
2, MSFT, SELL, 20, 4
3, MSFT, BUY, 16, 16
public enum Side {
BUY,
SELL
}
这是我的骆驼路线:
@Override
public void configure() throws Exception {
from("file:///Users/username/src/main/resources?fileName=orders.csv&noop=true&delay=1m")
.unmarshal()
.bindy(BindyType.Csv, Order.class).id("convertCsvToOrder")
.to("kafka:" + "{{kafka.topic.neworder}}" + "{{kafka.broker.location}}").id("sendNewOrderToTopic")
.routeId("new-order-csv");
}
我花了很长时间阅读 Apache Camel 文档,但找不到如何提供转换器以便正确构造 Pojo 中的 Side Enum 的示例。目前,当 Bindy 尝试解析 CSV 时,我遇到了以下异常。感谢是否有人可以提供指导。谢谢。
java.lang.IllegalArgumentException: Parsing error detected for field defined at the position: 3, line: 1
at org.apache.camel.dataformat.bindy.BindyCsvFactory.setDataFieldValue(BindyCsvFactory.java:257) ~[camel-bindy-2.23.1.jar:2.23.1]
at org.apache.camel.dataformat.bindy.BindyCsvFactory.bind(BindyCsvFactory.java:185) ~[camel-bindy-2.23.1.jar:2.23.1]
at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.lambda$consumeFile$0(BindyCsvDataFormat.java:243) ~[camel-bindy-2.23.1.jar:2.23.1]
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[na:1.8.0_144]
at java.util.stream.SliceOps$1$1.accept(SliceOps.java:204) ~[na:1.8.0_144]
at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_144]
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_144]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_144]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_144]
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[na:1.8.0_144]
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[na:1.8.0_144]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_144]
at java.util.stream.ReferencePipeline.forEachOrdered(ReferencePipeline.java:423) ~[na:1.8.0_144]
at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:176) ~[camel-bindy-2.23.1.jar:2.23.1]
at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:69) ~[camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) ~[camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) [camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) [camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:454) [camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:223) [camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:187) [camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174) [camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101) [camel-core-2.23.1.jar:2.23.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_144]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_144]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_144]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
Caused by: java.lang.IllegalArgumentException: No enum constant com.xxx.yyy.model.Side. SELL
at java.lang.Enum.valueOf(Enum.java:238) ~[na:1.8.0_144]
at org.apache.camel.dataformat.bindy.format.factories.EnumFormatFactory$EnumFormat.parse(EnumFormatFactory.java:49) ~[camel-bindy-2.23.1.jar:2.23.1]
at org.apache.camel.dataformat.bindy.format.factories.EnumFormatFactory$EnumFormat.parse(EnumFormatFactory.java:36) ~[camel-bindy-2.23.1.jar:2.23.1]
at org.apache.camel.dataformat.bindy.BindyCsvFactory.setDataFieldValue(BindyCsvFactory.java:252) ~[camel-bindy-2.23.1.jar:2.23.1]
... 31 common frames omitted