8-BeanIO Java tutorial
8-BeanIO Java tutorial
Home › Java & Big Data › Tutorials › Tutorials - Enterprise Java › TUT - Core Java › TUT - CSV and Java ›
fixed length stream formats, Object binding, filed validation, 150+ Java coding Q&As
integration with spring-batch, etc. Here is a basic tutorial to get
started.
Step 1: The sample CSV file to convert to an object of type Person. 300+ Big Data Interview
Q&As - Quick Prep FAQs
The first record is a header record, and the subsequent ones are
detail records. The file is person.csv under src/main/resources/data
300+ Big Data Interview
FAQs 📌
Step 2: Define the dependency jar in pom.xml file. Key Areas & Companion
Techs FAQs
https://www.java-success.com/beanio-java-tutorial/ 1/7
06/12/2024, 19:21 BeanIO Java tutorial
https://www.java-success.com/beanio-java-tutorial/ 2/7
06/12/2024, 19:21 BeanIO Java tutorial
1 package com.mycompany.app10;
2
3 public class Person
4 {
5 private String firstName;
6 private String surname;
7 private PersonType type;
8
9 public String getFirstName()
10 {
11 return firstName;
12 }
13
14 public void setFirstName(String firstName)
15 {
16 this.firstName = firstName;
17 }
18
19 public String getSurname()
20 {
21 return surname;
22 }
23
24 public void setSurname(String surname)
25 {
26 this.surname = surname;
27 }
28
29 public PersonType getType()
30 {
31 return type;
32 }
33
34 public void setType(PersonType type)
35 {
36 this.type = type;
37 }
38
39 @Override
40 public String toString()
41 {
42 return "Person [firstName=" + firstName + ", surname=
43 }
44
45 }
46
47
1 <beanio xmlns="http://www.beanio.org/2012/03">
2 <stream name="persons" format="csv">
3 <parser>
4 <property name="delimiter" value="," />
5 <property name="lineSeparator" value="\n" />
6 <property name="whitespaceAllowed" value="true" />
https://www.java-success.com/beanio-java-tutorial/ 3/7
06/12/2024, 19:21 BeanIO Java tutorial
7 </parser>
8 <typeHandler name="personTypeHandler" class="com.mycompany
9 <record name="header" class="map" maxOccurs="1">
10 <!-- 'rid' indicates this field is used to identify the re
11 <field name="recordType" rid="true" literal="H" />
12 <!-- 'format' can be used to provide Date and Number forma
13 <field name="fileDate" type="date" format="yyyy-MM-dd" />
14 </record>
15 <record name="detail" minOccurs="0" maxOccurs="unbounded"
16 class="com.mycompany.app10.Person">
17 <field name="firstName" />
18 <field name="surname" />
19 <field name="type" typeHandler="personTypeHandler" type="c
20 </record>
21 </stream>
22 </beanio>
23
1 package com.mycompany.app10;
2
3 import org.beanio.types.TypeConversionException;
4 import org.beanio.types.TypeHandler;
5
6 public class PersonTypeHandler implements TypeHandler
7 {
8
9 public Object parse(String text) throws TypeConversionExc
10 {
11 PersonType personType = PersonType.valueOf(text.trim(
12 return personType;
13 }
14
15 public String format(Object value)
16 {
17 return value != null ? ((PersonType) value).name() :
18 }
19
20 public Class<?> getType()
21 {
22 return PersonType.class;
23 }
24 }
25
1 package com.mycompany.app10;
2
3 public enum PersonType {
4 MALE, FEMALE;
5 }
https://www.java-success.com/beanio-java-tutorial/ 4/7
06/12/2024, 19:21 BeanIO Java tutorial
6
1
2 Tue Mar 12 00:00:00 EST 2013
3 [Person [firstName=John, surname=Smith, type=FAMILY], Person
4
Arulkumaran Kumaraswamipillai
Mechanical Engineer to self-taught Java engineer in 1999. Contracting since 2002 as a Java Engineer &
Architect and since 2016 as a Big Data Engineer & Architect. Preparation & key know-hows empowered me
to attend 150+ job interviews, choose from 130+ job offers & negotiate better contract rates. Author of the
book "Java/J2EE job interview companion", which sold 35K+ copies & superseded by this site with 3.5K+
registered users Amazon.com profile | Reviews | LinkedIn | LinkedIn Group | YouTube Email: java-
[email protected]
"You are paid to read & write lots of code & solve business problems in a
collaborative environment"
100+ Free Java Interview FAQs
100+ Free Big Data Interview FAQs
Don't be overwhelmed by the number of Q&As. Job interviews are not technical contests to see who gets most number of questions right.
Nobody knows everything. The Clarity of the answers you give with real-life examples will go a long way in getting you multiple job offers.
It pays to brush-up & choose from 2-6 job offers. Experienced interviewers can easily judge your real experience from a few open-ended
questions & the answers you provide.
1. Feeling stagnated?
2. How to earn more?
3. Freelancing Vs contracting?
https://www.java-success.com/beanio-java-tutorial/ 5/7
06/12/2024, 19:21 BeanIO Java tutorial
4. Self-taught professional?
5. Job Interview Tips
6. Resume Writing Tips
300+ Big Data Interview Q&As with code, scenarios & FAQs
100+ SQL Interview Q&As 01. 50+ SQL scenarios based interview Q&As – What is wrong with this SQL code? 02.…
(2,425)
00: Top 50+ Core Java interview questions & answers for 1 to 3 years experience
Top 50 core Java interview questions covering core Java concepts with diagrams, code, examples, and scenarios. If you don't get…
(1,971)
Java 8 String streams and finding the first non repeated character with functional programming
Q1.Find the first non repeated character in a given string input using Java 8 or later? A1.Extends Find the first…
(1,669)
Membership Levels
Membership prices listed below are in Australian Dollars (A$). If you purchase in other currencies like Indian rupees, the equivalent…
(718)
https://www.java-success.com/beanio-java-tutorial/ 6/7
06/12/2024, 19:21 BeanIO Java tutorial
0: 50+ SQL scenarios based interview Q&As – What is wrong with this SQL code?
This extends 18+ SQL best practices & optimisation interview Q&As. You can practice these SQLs by setting up the data…
(370)
Disclaimer
The contents in this Java-Success are copyrighted and from EmpoweringTech pty ltd. The EmpoweringTech pty ltd has the right to correct or enhance the current content without
any prior notice. These are general advice only, and one needs to take his/her own circumstances into consideration. The EmpoweringTech pty ltd will not be held liable for any
damages caused or alleged to be caused either directly or indirectly by these materials and resources. Any trademarked names or labels used in this blog remain the property of
their respective trademark owners. Links to external sites do not imply endorsement of the linked-to sites. Privacy Policy
© 2024 800+ Big Data & Java Interview FAQs Responsive WordPress Theme powered by CyberChimps
https://www.java-success.com/beanio-java-tutorial/ 7/7