I have the following route
from("file:" + baseInputPath + "/exchangerates" + "?noop=true")
.idempotentConsumer(header(CAMEL_FILE_NAME),
FileIdempotentRepository.fileIdempotentRepository(new File(
baseInputPath + "/tracker/exchangeratefiles.txt")))
.log("Processing exchange rate file: ${header.CamelFileName}").unmarshal()
.bindy(BindyType.Csv, ExchangeRateBindy.class).process(exchange -> {
ExchangeRateBindy exchangeRateBindy = exchange.getIn()
.getBody(ExchangeRateBindy.class);
if (exchangeRateBindy != null) {
exchangeRateService.save(exchangeRateBindy.toExchangeRate());
} else {
log.error("Invalid exchange rate: {}", exchange.getIn().getBody());
}
});
and the following bindy class
@Data
@CsvRecord(separator = "\\*", skipFirstLine = false)
public class ExchangeRateBindy {
@DataField(pos = 1)
private String currencyId;
@DataField(pos = 2)
private String currencyName;
@DataField(pos = 3)
private double buyRate;
@DataField(pos = 4)
private double midRate;
@DataField(pos = 5, defaultValue = "0")
private double sellRate;
public ExchangeRate toExchangeRate() {
return ExchangeRate.builder().currencyId(currencyId).currencyName(currencyName).buyRate(buyRate)
.midRate(midRate).sellRate(sellRate).build();
}
}
and csv data
CAD*Canadian Dollar.*1.0332*1.0332*1.0332
AUD*Australian Dollars.*812.7459194*837.88239115*Test
BWP*BOTSWANA PULA*90.29159051*93.084113925*95.87663734
How do I allow my route to skip the second record which has an invalid last field with the value 'Test' instead of a numeric value? As it is the code just throws a NumberFormatException and does not process any of the records.