javaparsingbean-iofixed-length-file

Multiple length="unbounded" in fixed length file


I'm experiencing a little issue and I'm asking for your help! Using BeanIO 2.1 and working on a fixed-length file, I'm currently trying to retrieve a record that is structured like this :28C:5n/5n

Examples:

Here is a snippet of the code:

<record name="statementNumber" class="com.batch.records.StatementNumber" occurs="1">
    <field name="tag" type="string" length="5" rid="true" literal=":28C:" ignore="true" />
    <field name="statementNr" type="int" length="unbounded" maxLength="5" />
    <field name="separator" type="string" length="1" rid="true" literal="/" ignore="true" />
    <field name="sequenceNr" type="int" length="unbounded" maxLength="5" />
</record>

When running my parser, I get this exception:

Cannot determine field position, field is preceded by another component with indeterminate occurrencesor unbounded length 

My question is: how can I tell BeanIO that the field '/' is actually the delimiter between the two variable fields ?

Thanks in advance


Solution

  • You can only have 1 field of an unbounded length on a line. The BeanIO documentation says:

    The length of the last field in a fixed length record may be set to unbounded to disable padding and allow a single variable length field at the end of the otherwise fixed length record.

    Honestly, I'm not sure if this can be done using BeanIO. Is it an option to read the 5n/5n fields completely into Java as 1 field and splitting it on / in your code, instead of BeanIO?