Problema with record ID
Opened this issue · 4 comments
If I have a fixed length records like this
Xmessage
XDother message
XDanother message
Where X, XD and XR are the Ids, BeanIO cannot identify the record type correctly.
Please provide your mapping.xml file or the equivalent code with the annotations
class RecordX {
public static final String ID_REG = "X";
@Field(at = 0, length = 1, rid = true, literal = ID_REG)
private String idReg;
class RecordXD {
public static final String ID_REG = "XD";
@Field(at = 0, length = 2, rid = true, literal = ID_REG)
private String idReg;
class RecordXR {
public static final String ID_REG = "XR";
@Field(at = 0, length = 2, rid = true, literal = ID_REG)
private String idReg;
Your classes doesn't specify any min/max occurrences. How are your data then structured?
Is there only a single RecordX
message and then any number of RecordXD
and RecordXR
records?
How do you define your StreamBuilder
?
The above work for me with a simple change to RecordX
:
@Record(minOccurs = 1, maxOccurs = 1)
public class RecordX {
Is the test data correct? Should the last message not start with XR
? More example data could also be useful if the above does not answer/solve your problem.
There are any number (0..unbonded) of X/XD/XR records in any order. I just "new StreamBuilder()" and call addRecord(RecordX.class), ... for each class. The order I call addRecord() does not seem to matter also. I workaround the problem by creating two streamBuilder and then creating two unmarshallesr. I can check for the record type myself and use the correct unmarshaller:
public <T extends Record> T toRecord(String line) {
if (line.startsWith(RecordXD.ID_REG) || line.startsWith(RecordXR.ID_REG))
// has only RecordXD RecordXR
return (T) unmarshallerXdXr.unmarshal(line);
// has only RecordX
return (T) unmarshaller.unmarshal(line);
}
Anyway, this definitely looks like a bug to me. Since sometimes you cannot control how the input file is created, you need to predict such situations where IDs might start with the same string.