Apache camel:bindy illegal argument exception

北慕城南 提交于 2019-12-10 11:34:49

问题


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&amp;initialDelay=10"/>
        <log message="csv string ============= ${body}"/>
        <unmarshal ref="bindyDataformat"/>
        <log message="${body}"/>
        <bean ref="govtEmpBean" method="printCSVObject" beanType="govtEmpBean" id="govtEmp"/>
    </route>

回答1:


You need to specify the csv record as follows

@CsvRecord(separator = "\\|")


来源:https://stackoverflow.com/questions/20627864/apache-camelbindy-illegal-argument-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!