Nested Segments

39 views
Skip to first unread message

sarath kumar

unread,
Feb 5, 2020, 2:51:14 AM2/5/20
to beanio-users
Hi,
I am using Beanio for the flat file generation with fixed length format. I am using below format to generate the file actually it was working fine. i don't know what happened it is not working. Can anyone assist me to workout this ? 

Format:
</beanio>
<stream name="FileStream" format="fixedlength">
<record name="FileRecord" class="com.test.IFile">

      <segment name="header1" class="com.test.model.Header1">
      </segment>

      <segment name="headerList" collection="list" minOccurs="1" maxOccurs="unbounded" class="com.test.Header2">

         <segment name="detailList" collection="list" class="com.test.Detail" >
         </segment>

         <segment name="summary" class="com.test.Summary">
         </segment>

      </segment>

      <segment name="trailer" class="com.test.Trailer">
      </segment>

    </record>
</stream>
</beanio>


Thanks,
Sarathkumr P.

Nico Schlebusch

unread,
Feb 5, 2020, 3:16:10 AM2/5/20
to bea...@googlegroups.com
Hi Sarathkumr

You will have to provide more information. We need the full mapping file, the POJO objects, test (input) data, the expected outcome and the exception if there is one. Tell us what is not working, we can't guess. The more information you supply, the easier it is for someone to reproduce the error and help.

Kind regards,
Nico Schlebusch


--
You received this message because you are subscribed to the Google Groups "beanio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beanio+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beanio/306536b4-4af4-4d85-bbde-a9a417ad19f6%40googlegroups.com.

sarath kumar

unread,
Feb 5, 2020, 5:39:34 AM2/5/20
to beanio-users
Hi Nico,
Thanks for the quick response. Please find the below sample java class files mapping file and sample output.

FYI, 
1. Here i have provided data are exact sample of my prototype. 
2. Output should be in the single line.

Output:

Sarathkumar                   Palani                        San Jose                     CAUSA       ~Sarathkumar                   Palani                        Male      SchoolName                    San Jose                      ~addressLine1     addressLine2     addressLine3        CA   ~                                                  ~

Java POJO Class files:

public class IFile{

private Header1 header1;

    private List<Header2> headerList;

    private trailer trailer;
//getter and setter methods

}

public class Header1{

private String firstName;

    private String lastName;

    private String city;

    private String state;

    private String country;
//getter and setter methods

}

public class Header2{

private String firstName;

    private String lastName;

    private String gender;

    private String schoolName;

    private String city;
private List<detail> detailList;
private Summary summary;
//getter and setter methods


}

public class Detail{

private String addressLine1;

    private String addressLine2;

    private String addressLine3;

    private String emailAddress;

    private String mobileNumber;
private String faxNumber;
private String city;
private String state;
private String zip;
//getter and setter methods

}

public class Summary{

private String fullName;
private String address;
private String mobileNumber;

}

public class Trailer{

private String variable1;
private String variable2;
private String variable3;

}

Sample Mapping file:
</beanio>
<stream name="FileStream" format="fixedlength">
    <record name="FileRecord" class="com.test.IFile">

      <segment name="header1" class="com.test.model.Header1">
<field name="firstName" padding=" " length="30" />
<field name="lastName" padding=" " length="30" />
<field name="city" padding=" " length="30" />
<field name="state" padding=" " length="2" />
<field name="country" padding=" " length="10" />
<field name="tilt" padding="~" length="1" />
      </segment>

      <segment name="headerList" collection="list" minOccurs="1" maxOccurs="unbounded" class="com.test.Header2">
<field name="firstName" padding=" " length="30" />
<field name="lastName" padding=" " length="30" />
<field name="gender" padding=" " length="10" />
<field name="schoolName" padding=" " length="30" />
<field name="city" padding=" " length="30" />
<field name="tilt" padding="~" length="1" />
         <segment name="detailList" collection="list" class="com.test.Detail" >
<field name="addressLine1" padding=" " length="20" />
<field name="addressLine2" padding=" " length="30" />
<field name="addressLine3" padding=" " length="30" />
<field name="emailAddress" padding=" " length="30" />
<field name="mobileNumber" padding=" " length="10" />
<field name="faxNumber" padding=" " length="10" />
<field name="city" padding=" " length="30" />
<field name="state" padding=" " length="2" />
<field name="zip" padding=" " length="9" />
<field name="tilt" padding="~" length="1" />
         </segment>

         <segment name="summary" class="com.test.Summary">
<field name="fullName" padding=" " length="30" />
<field name="address" padding=" " length="30" />
<field name="mobileNumber" padding=" " length="10" />
<field name="tilt" padding="~" length="1" />
         </segment>

      </segment>

      <segment name="trailer" class="com.test.Trailer">
<field name="variable1" padding=" " length="5" />
<field name="variable2" padding=" " length="5" />
<field name="variable3" padding=" " length="5" />
<field name="tilt" padding="~" length="1" />
      </segment>

    </record>
    </stream>
</beanio>








To unsubscribe from this group and stop receiving emails from it, send an email to bea...@googlegroups.com.

Nico Schlebusch

unread,
Feb 5, 2020, 5:00:47 PM2/5/20
to bea...@googlegroups.com
Hi,

What are you trying to achieve with these lines at the end of each segment in your mapping.xml file when there isn't a field/attribute/property called "tilt"  in your POJO's?

<field name="tilt" padding="~" length="1" />
Because I'm getting this exception:
org.beanio.BeanIOConfigurationException: No such property 'tilt' in class 'com.test.model.Header1'

I think you should also read the documentation very carefully where it explains "padding" - http://beanio.org/2.1/docs/reference/index.html#FixedLengthFields

Kind regards,
Nico Schlebusch

sarath kumar

unread,
Feb 5, 2020, 11:33:11 PM2/5/20
to bea...@googlegroups.com
Hi Nico,
Actually, i have these fields in my pojo classes. still i am not able to get the correct output.
 
sarath kumar


--
You received this message because you are subscribed to the Google Groups "beanio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beanio+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beanio/48305ebd-866b-439d-b99d-f8697d49e8a7%40gmail.com.

sarath kumar

unread,
Feb 6, 2020, 12:06:30 AM2/6/20
to bea...@googlegroups.com
Nico,
Please find the updated mapping and pojo files.

 
sarath kumar

beanio-mapper.txt
beanio-pojo.txt

Nico Schlebusch

unread,
Feb 6, 2020, 5:20:04 AM2/6/20
to bea...@googlegroups.com
Hi,

Try adding required="true" to the 'tilt' fields...

Kind regards,
Nico Schlebusch

sarath kumar

unread,
Feb 7, 2020, 3:59:29 AM2/7/20
to beanio-users
Hi Nico,
Thanks for the update, it is not suitable for requirement i did it in different way.

Thanks,
Sarathkumar P.
Reply all
Reply to author
Forward
0 new messages