Bindy does not support quoted value with separator char in CSV datasource
-------------------------------------------------------------------------
Key: CAMEL-4655
URL: https://issues.apache.org/jira/browse/CAMEL-4655
Project: Camel
Issue Type: Bug
Components: camel-bindy
Affects Versions: 2.8.2
Environment: Mac Snow Leopard
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
Maven 3.0.1
Reporter: Olivier SCHMITT
i'm currently writing a tuto on Camel (2.8.2).
Showing HTTP4 component usage by downloading US Gov public data, i found a
problem :
from("quartz://dataTimer?cron=0+*+*+*+*+?").to("direct:datas");
from("direct:datas")
.to("http4://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt")
.unmarshal(new
BindyCsvDataFormat("net.thejeearchitectcookbook.camel.earthquake"))
.process(new Processor() {
public void process(Exchange exchange) throws Exception
{
Message message = exchange.getIn();
// ...
}
});
The data format is like :
nc,71678421,0,"Wednesday, November 9, 2011 14:53:13
UTC",37.5727,-118.8170,1.3,6.60,14,"Central California"
I want to get all datas as java.lang.String but the date value raises exception
:
java.lang.IllegalArgumentException: No position 11 defined for the field: 14,
line: 2 must be specified]
My separator is "," but some values are nested inside " ". Unfortunately there
are , inside the " ".
Bindy get lost !
How can i get String values nested inside " " and containing "," ?
I can note that Camel CSV component deals with it without any problems.
Here is my pojo :
package net.thejeearchitectcookbook.camel.earthquake;
import java.io.Serializable;
import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
import org.apache.camel.dataformat.bindy.annotation.DataField;
@CsvRecord( separator = ",")
public class EarthquakeInfos implements Serializable {
@DataField(pos = 1)
private String src;
@DataField(pos = 2)
private String eqid;
@DataField(pos = 3)
private String version;
@DataField(pos = 4)
private String datetime;
@DataField(pos = 5)
private String lat;
@DataField(pos = 6)
private String lon;
@DataField(pos = 7)
private String magnitude;
@DataField(pos = 8)
private String depth;
@DataField(pos = 9)
private String nst;
@DataField(pos = 10)
private String place;
public String getSrc() {
return src;
}
public void setSrc(String src) {
this.src = src;
}
public String getEqid() {
return eqid;
}
public void setEqid(String eqid) {
this.eqid = eqid;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLon() {
return lon;
}
public void setLon(String lon) {
this.lon = lon;
}
public String getDepth() {
return depth;
}
public void setDepth(String depth) {
this.depth = depth;
}
public String getNst() {
return nst;
}
public void setNst(String nst) {
this.nst = nst;
}
public String getDatetime() {
return datetime;
}
public void setDatetime(String datetime) {
this.datetime = datetime;
}
public String getMagnitude() {
return magnitude;
}
public void setMagnitude(String magnitude) {
this.magnitude = magnitude;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
}
I can find that CSV Camel component performs well with the same datasource :
from("direct:datas")
.to("http4://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-M1.txt")
.unmarshal().csv().process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
List<List<String>> datas = (List<List<String>>)
message.getBody();
// Skip header
datas = datas.subList(1, datas.size() - 1);
// Process my data
for (List<String> row : datas) {
// Process Row
String datetime = row.get(3);
String region = row.get(9);
String magnitude = row.get(6);
}
}
});
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira