Writing repeated segments using BeanIO

1,308 views
Skip to first unread message

Juzer Mukadam

unread,
Jul 22, 2013, 3:01:56 AM7/22/13
to bea...@googlegroups.com
Hi all,

I have been facing an issue trying to write repeating segments to a flat file using beanIO.

I have a TestBean with instances:
        
        private long clientNum;
private int oldClientId;
private String clientLastName;
private String dobHelper;
private String sex;
private List<TestChildBean> testChildBeans = new ArrayList<TestChildBean>();
....
        (generated getters and setters)

The TestChildBean has:
private String child1;
private String child2;
private String child3;
        ...
        (generated getters and setters)

and my beanio mapping xml is as follows:

<stream name="TestSendFile" format="fixedlength">
<record name="TestBean" class="example.TestBean" >
  
<field name="clientNum" length="10" type="long" justify="right"
padding="0" />
<field name="oldClientId" length="10" type="int" justify="right"
padding="0" />
<field name="clientLastName" length="17" type="string" justify="left" />
<field name="dobHelper" length="8" type="string" />
<field name="sex" length="1" type="string" />
   <segment name="testChildBeans" collection="list" minOccurs="1" maxOccurs="unbounded" class="example.TestChildBean" >
<field name="child1" type="string" length="9" padding="0"/>
<field name="child2" type="string" length="9" padding="0"/>
<field name="child3" type="string" length="9" padding="0"/>
</segment>
</record>
</stream>
</beanio>

Whereas the remaining elements render fine in the generated flat file, the repeating segment doesn't come at all.

beanIO is capable of writing repeated segments, isn't it? Or does it just read? Or am I missing something obvious? When I debug the code, the getter for the testChildBeans doesn't get called at all. 

Any pointers would be appreciated.

Thanks,
J

Juzer Mukadam

unread,
Jul 22, 2013, 4:36:00 AM7/22/13
to bea...@googlegroups.com
Just to add, I have problem rendering a custom object to the flat file even if I do not set it to repeating. 

i.e. just private TestChildBean testChildBean; instead of private List<TestChildBean> testChildBeans = new ArrayList<TestChildBean>();


I have been using beanIO up until now for primitive/basic Wrapper types up until now and have never had issues. It's my first time experimenting with a custom type.


Thanks,
J

Kevin

unread,
Jul 22, 2013, 4:31:26 PM7/22/13
to bea...@googlegroups.com
That should work just find.

When you are marshalling TestBean, are you sure you have an instance or List of TestChildBeans set on it?  What output do you get?

Thanks,
Kevin

Juzer Mukadam

unread,
Jul 23, 2013, 1:46:57 AM7/23/13
to bea...@googlegroups.com
I do.
        List<InterfaceMarker> list = new ArrayList<InterfaceMarker>();
TestBean testBean = new TestBean();
testBean.setClientNum(333333);
testBean.setOldClientId(7777777);
testBean.setClientLastName("Client Name");
testBean.setDobHelper("20130908");
testBean.setSex("M");

//List<TestChildBean> childBeanList = new ArrayList<TestChildBean>();
ArrayList<TestChildBean> childBeanList = new ArrayList<TestChildBean>();
TestChildBean testChildBean1 = new TestChildBean();
testChildBean1.setChild1("CCCCCCCC");
testChildBean1.setChild2("DDDDDDDD");
testChildBean1.setChild3("EEEEEEEE");
childBeanList.add(testChildBean1);
TestChildBean testChildBean2 = new TestChildBean();
testChildBean2.setChild1("FFFFFFF");
testChildBean2.setChild2("GGGGGGG");
testChildBean2.setChild3("HHHHHHH");
childBeanList.add(testChildBean2);
        testBean.setTestChildBeans(childBeanList); 
//testBean.setTestChildBean(testChildBean1);
list.add(testBean);
  .... 
I write the list as:
File outputFile = new File(...);
out = factory.createWriter("TestSendFile", outputFile);
for (InterfaceMarker bean : list) {
out.write(bean);
}
out.flush();
out.close();


This is how the generated flat file looks like:

00003333330007777777Client Name      20130908M


Thanks,
J

Kevin

unread,
Jul 23, 2013, 2:04:23 PM7/23/13
to bea...@googlegroups.com
Hmm, that all looks good- what version of BeanIO are you using?

Thanks,
Kevin

Juzer Mukadam

unread,
Jul 24, 2013, 12:52:03 AM7/24/13
to bea...@googlegroups.com
2.0.3

Kevin

unread,
Jul 24, 2013, 10:06:14 PM7/24/13
to bea...@googlegroups.com
I'm unable to reproduce the issue with release 2.0.6.  Although I don't think there have been any bug fixes related to this, please try with 2.0.6 just to see, and if it still doesn't work, perhaps you can zip up a simple test case that reproduces the issue and post it here.

Thanks,
Kevin

Juzer Mukadam

unread,
Jul 29, 2013, 8:18:08 AM7/29/13
to bea...@googlegroups.com
Hi Kevin,

I had said at the start of my post that it's most likely a silly error, and a silly error it was. The shared library containing the beanio jar was actually 1.x and not 2.0.3 as we had been believing all this while. I replaced the jar in the library and the repeating segments started rendering fine.

Thanks for all your help. It's a wonderful API you have here.

Regards,
Juzer

Kevin

unread,
Jul 29, 2013, 10:22:07 PM7/29/13
to bea...@googlegroups.com
Glad to hear you got it worked out.

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