Apache的骆驼:bindy非法参数异常 [英] Apache camel:bindy illegal argument exception

查看:207
本文介绍了Apache的骆驼:bindy非法参数异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做的到CSV POJO之间的数据格式转换,反之亦然。在此同时,转换CSV到目标文件(解组)我得到的int数据类型非法参数异常。只有字符串其工作罚款。
下面是我的POJO

  @CsvRecord(分隔符=// |CRLF =UNIX,generateHeaderColumns = FALSE)
公共类EmployeeVO实现Serializable {    私有静态最后的serialVersionUID长= -663135747565879908L;    @DataField(POS = 1)
    私人字符串名称;    @DataField(POS = 3)
    私人整数年龄;    @DataField(POS = 2)
    私人字符串等级;
        //吸气二传手
}

CSV数据

  SUMIT | 4 standrad | 22

上述的csv从上述POJO生成。但在CSV转换成POJO我得到folloing异常时

  java.lang.IllegalArgumentException异常:3,行:在位置定义的字段检测分析错误1

以下是我的骆驼 - 供大家参考上下文文件

名帅

 <&路线GT;
        <从URI =CXF:豆:rtoemplyeeService/>
        < convertBodyTo TYPE =java.lang.String中ID =stringInput/>
        <豆REF =govtEmpBean方法=getEmployeeCSVbeanType =govtEmpBeanID =govtEmp/>
        <日志消息= /&GT编组================== $ {}身前;
        <元帅REF =bindyDataformat>
            < bindy TYPE =CSV包=com.mycompany.converter.vo/>
        < /元帅>
        <日志消息= /&GT编组================== $ {}身体后;
        <到URI =文件:// D:/ JATO_WORK / repo_bkp / CSV //>
        < setBody>
            <简单且gt;对于文件系统和LT生成CSV输出; /简单>
        < / setBody>
    < /路由>

联合国名帅

 <路线ID =csvtoobject>
        <从URI =文件:// D:/?JATO_WORK / repo_bkp / CSV延迟= 10000&放大器;放大器;在initialDelay = 10/>
        <日志消息=CSV字符串============= $ {}体/>
        <解组REF =bindyDataformat/>
        <日志消息=$ {}体/>
        <豆REF =govtEmpBean方法=printCSVObjectbeanType =govtEmpBeanID =govtEmp/>
    < /路由>


解决方案

您需要按以下方式指定CSV记录

  @CsvRecord(分隔符=\\\\ |)

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>

解决方案

You need to specify the csv record as follows

@CsvRecord(separator = "\\|")

这篇关于Apache的骆驼:bindy非法参数异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆