I am doing data format conversion between POJO to CSV and vice versa. In this while converting CSV to Object file(Unmarshalling) i am getting illegal argument exception for int data type. Only for string its working fine. Below is my POJO
@CsvRecord(separator="//|",crlf="UNIX",generateHeaderColumns=false)
public class EmployeeVO implements Serializable{
private static final long serialVersionUID = -663135747565879908L;
@DataField(pos=1)
private String name;
@DataField(pos=3)
private Integer age;
@DataField(pos=2)
private String grade;
// getter setter
}
csv data
sumit|4th standrad|22
the above csv is generated from the above POJO. But at the time of converting CSV to POJO i am getting folloing exception
java.lang.IllegalArgumentException: Parsing error detected for field defined at the position: 3, line: 1
following are my camel - context file for your reference
marshal
<route>
<from uri="cxf:bean:rtoemplyeeService"/>
<convertBodyTo type="java.lang.String" id="stringInput"/>
<bean ref="govtEmpBean" method="getEmployeeCSV" beanType="govtEmpBean" id="govtEmp"/>
<log message="before marshalling ================== ${body}"/>
<marshal ref="bindyDataformat">
<bindy type="Csv" packages="com.mycompany.converter.vo"/>
</marshal>
<log message="after marshalling ================== ${body}"/>
<to uri="file://D:/JATO_WORK/repo_bkp/csv/"/>
<setBody>
<simple>CSV output is generated at file system </simple>
</setBody>
</route>
un marshal
<route id="csvtoobject">
<from uri="file://D:/JATO_WORK/repo_bkp/csv?delay=10000&initialDelay=10"/>
<log message="csv string ============= ${body}"/>
<unmarshal ref="bindyDataformat"/>
<log message="${body}"/>
<bean ref="govtEmpBean" method="printCSVObject" beanType="govtEmpBean" id="govtEmp"/>
</route>
You need to specify the csv record as follows
@CsvRecord(separator = "\\|")
来源:https://stackoverflow.com/questions/20627864/apache-camelbindy-illegal-argument-exception