Appreciate if someone could point and recommend on how to parse a flat pipe delimited file to JAVA Pojo.
eg. Flat File 0001|XYZ|120
this is required to be read into a POJO having
public class pojo {
private String acct;
private String customer;
private int balance;
}
I can read entire input file as a collection, however, would end up setting each token into a pojo member. Instead, I would like to parse into pojo members. Something similar to CASTOR XML mapping to POJO.
Appreciate any help in this regards. Thanks in advance
You can use Bean IO. I have been using this extensively.
Configure your XML as something like this
<stream name="employees" format="delimited" strict="true">
<parser>
<property name="delimiter" value="|" />
</parser>
<record name="test" class="example.Pojo" minOccurs="1" maxOccurs="1">
<field name="act" />
<field name="customer" />
<field name="balance" type="int" />
</record>
</stream>
Refer here for more details.
OopenCSV http://opencsv.sourceforge.net/ has what you are looking for. Just change the delimiter to |
from ,
. And you should be all set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With