Search code examples
splitjavabeansgroupingrecordspring-batch

Record splitting and grouping in spring batch


I have a requirement to split my input file which contains records of different length and type some beans. I am able to map each record to different bean using CompositeItemReader. But there is some parent-child relation exists between these records. I want to form a bean which contains child beans. Any help is appreciated.

This is my sample input file.

AB,01,05,HHGFG,05 CD,452,63,FDD,07,54,76,EQWED PT,GGG,76,YYY CD,08,06,ASW,97,55,66,BT AB,96,87,KKK,03 PT,TIPWQ,19,YEQ PT,ROPRG,39,PRVM

CD,08,06,ASW,97,55,66,BT

Here AB is considered as parent record. My segments start with AB*, CD*, PT*


Solution

  • Top level domain object creation is responsability of ItemReader so this type of aggregation should be done in reading phase.
    In SB-sample-projects there is a multilineOrder sample where you have a skeleton about how to resolve this type of problem; of course you have to resolve "manually" parent/child relationship between objects and manage errors during read.
    Another example at Spring Batch :Aggregated reader / writer Issue