Bean IO complex single record ,multi segments (0-n occurences) pipe delimited

333 views
Skip to first unread message

Indrani Boppana

unread,
Oct 14, 2014, 2:10:53 PM10/14/14
to bea...@googlegroups.com, indrani...@equifax.com
I have a scenario to map user information to Map of Objects (Map or List<Map>).

I have say user info as follows
CommonHeader(CX) block followed by 0 or more ID blocks followed by 0 or more Address blocks

Below are valid formats for user records

CX|19981222|19981222|ID|DriversLicence|111111111|ID|Passport|ABC12345|AD|123 Main Street|Atlanta|GA|30316|AD|100 PeachTree RD|Atlanta|Ga|3007|
CX|19981222|19981222|ID|DriversLicence|111111111|ID|Passport|ABC12345|
CX|19981222|19981222|AD|123 Main Street|Atlanta|GA|30316|AD|100 PeachTree RD|Atlanta|Ga|3007|

Is it possible to map such scenarios using beanio ?
Whats the best solution to handle these cases ?


I am using Beanio-2.1

My beanio mapping file is as follows

 <stream name="userrRecord" format="delimited">
        <parser>
            <property name="delimiter" value="|"/>
        </parser>
        <record name="urecord" class="map" minOccurs="0" maxOccurs="unbounded" >
            <segment name="CX" class="map">
                <field name="CX"/>
                <field name="DateFirstReported" type="date" format="yyyyMMdd"/>
                <field name="DateLastReported" type="date" format="yyyyMMdd"/>
           </segment>    
            <segment name="ID" class="map"  minOccurs="0" maxOccurs="unbounded" collection="list">
                <field name="ID"/>
                <field name="IDType"/>
                <field name="DocumentID"/>
            </segment>
            < segment name="AD" class="map" minOccurs="0" maxOccurs="unbounded" collection="list">
                <field name="AD"/>
                <field name="Street"/>
                <field name="City"/>
                <field name="State"/>
                <field name="Zipcode"/>               
            </segment>
        </record>
    </stream>

When I try to unmarshall a record with 2 ID segmenst and 0 AD segments running into InvalidRecord exception.

Any help is highly appreciated.

Thanks
  Indrani

Kevin

unread,
Oct 22, 2014, 10:28:27 PM10/22/14
to bea...@googlegroups.com, indrani...@equifax.com
Hi Indrani,

Sorry, but BeanIO doesn't support segment matching/identification within a record.

The only possibility might be to write your own parser (or extend BeanIO's DelimitedReader/Writer) and convert the segments on the fly to records.

For example, if you converted the input from

CX|19981222|19981222|ID|DriversLicence|111111111|ID|Passport|ABC12345|AD|123 Main Street|Atlanta|GA|30316|AD|100 PeachTree RD|Atlanta|Ga|3007|

to 

CX|19981222|19981222
ID|DriversLicence|111111111
ID|Passport|ABC12345
AD|123 Main Street|Atlanta|GA|30316
AD|100 PeachTree RD|Atlanta|Ga|3007

you could use BeanIO's record matching and grouping to accomplish what you want.

Thanks,
Kevin
Reply all
Reply to author
Forward
0 new messages