I am using BeanIO to parse a fixed width text file. For example, the file coming into my project looks like the following fixed width text:
CD DummyValue3
EF DummyValue4 DummyValue5 DummyValue6
AB DummyValue1 DummyValue2
...
In my mappings files, I have a record
declared for each recordID (i.e. AB, CD, EF)
<record name="dummyRecord" template="AB"
class="com.company.project.DummyRecordClass" minOccurs="0"
maxOccurs="1" />
I then have a template
for each record:
<template name="AB">
<field name="recordID" length="3" rid="true" literal="AB"
lenientPadding="true" minOccurs="0" />
<field name="value1" length="12" lenientPadding="true"
minOccurs="1" required="true"/>
<field name="value2" length="12" lenientPadding="true"
minOccurs="1" required="true"/>
</template>
Because value1
and value2
have a minOccurs = 1
as well as a required="true"
(Yes I know this is redundant, but it was already in the code and we have thousands of these fields) they must exist if I have an AB segment.
So if I was to pass the following file into my program:
CD DummyValue3
EF DummyValue4 DummyValue5 DummyValue6
AB DummyValue1
I receive the following InvalidRecordGroupException:
org.beanio.InvalidRecordGroupException: Invalid 'ediMessage' record group at line 1
However, since the missing field is actually on line 3, this can be a complete pain to debug when you have 500-600 lines of data coming into the application.
Is there any way to have beanIO output the correct line number, or even the template
and field
value when a mandatory field is missing?