【问题标题】:Camel Bindy Fixed Length Format : How to use inherited classes?Camel Bindy 固定长度格式:如何使用继承的类?
【发布时间】:2015-12-29 17:55:48
【问题描述】:

我有两个类 CommonRequest 和 AccountRequest

@FixedLengthRecord(paddingChar=' ',ignoreTrailingChars=true)
public class CommonRequest {

@Id
private String corelationID;

@DataField(pos=1,length=8)
private String cmNumber;

@DataField(pos=2,length=16)
private String accountNumber;

}

还有 AccountRequest.java

@FixedLengthRecord(paddingChar=' ',ignoreTrailingChars=true)
public class AccountRequest extends CommonRequest {

@Id
private String corelationID;

@DataField(pos=3,length=14)
private String accountType;

@DataField(pos=4,length=15)
private String accountLocation;

}

当我尝试解组类似 cmNumberaccountNumberaccountTypeaccountLocation

之类的记录时

它会正确地解组共同请求,但是当我尝试解组 AccountRequest 时,它会从头开始获取位置,而不是从共同请求中留下的位置继续。

这与 AccountRequest 中的整个字段不匹配。

【问题讨论】:

    标签: java apache apache-camel fixed-length-record bindy


    【解决方案1】:

    更改位置以匹配长度,但您仍然不会设置基类中的字段,它们将为空,但将设置子类字段。查看此站点以了解如何完成。http://people.apache.org/~dkulp/camel/bindy.html

    【讨论】:

    • 尝试改变位置,它实际上跳过了 2 个字符,因为我们在子类中给出了 pos=3。它在 2.13.0 版本中运行良好,但现在在 2.16.0 中它给了我一个问题
    • 提供子类中的实际位置编号,如 pos=25 代替 pos=3。
    【解决方案2】:

    将此视为文本记录 01 32 桑达尔穆尔蒂

    @FixedLengthRecord(length = 20,ignoreTrailingChars=true)
    public class Employee {
    @DataField(pos = 1, length = 2)
    private int serialNo;
    @DataField(pos = 4, length = 2)
    private int age;
    @DataField(pos = 7, length = 6)
    private String firstName;
    ....getters and setters
    }
    
    @FixedLengthRecord(length=20)
    public class Employee2 extends Employee{
    @DataField(pos=14, length=7)
    private String lastName;
    ....
    getters and setters..
    }
    

    现在,如果您使用 Camel 使用 Employee 类解组文本文件,结果将是序列号、年龄和名字将设置为模型。 132桑达 如果您使用骆驼使用 Employee2 类解组文本文件,结果将是姓氏将设置为模型。 鼹鼠

    这是camel 2.16.0,如果有任何问题请告诉我,但不会设置基类中的字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多