2015-12-29 48 views
1

我有兩個類CommonRequest和AccountRequest駱駝Bindy固定長度格式:如何使用繼承類?

@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它從開始的位置開始,而不是從commo中留下的位置繼續請求。

而這不匹配AccountRequest中的整個字段。

回答

0

更改位置以匹配長度,但仍然不會有基類集中的字段,它們將爲null,但將設置子類字段。檢查這個網站看看它是如何完成的。 http://people.apache.org/~dkulp/camel/bindy.html

+0

試圖改變位置,它實際上跳過了2個字符,因爲我們在子類中給了pos = 3。它在2.13.0版本中工作正常,但現在在2.16.0中給我一個問題 –

+0

在pos = 3的地方提供像pos = 25這樣的子類中的實際位置編號。 – Sundar

0

認爲這是文本記錄 01 32孫大信Moorthy

@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.. 
} 

現在,如果你使用駱駝使用Employee類的結果,解組文本文件將是序列號和年齡和名字將被設置模擬。 132Sundar 如果您使用駱駝解組使用Employee2類的文本文件,結果將是姓氏將被設置爲模型。 Moorthy

這是駱駝2.16.0,請讓我知道是否有任何進一步的問題,但基類中的字段將不會被設置。