-
Notifications
You must be signed in to change notification settings - Fork 76
SimpleFlatMapper CsvMapper 1 N relationship
Arnaud Roger edited this page Mar 13, 2015
·
1 revision
Since version 1.7.0 it is possible to map 1-N relationship and aggregating the N into a list in the 1 for csv file.
ie.
for the following rows
id | name | students_id | students_name |
---|---|---|---|
1 | professor1 | 10 | student1 |
1 | professor1 | 20 | student2 |
the CsvMapper will return 2 professors with 1 students each.
0 : Professor1 { Students[ Student1 ] }
1 : Professor1 { Students[ Student2 ] }
But from 1.7.0 if you define the column "id" as a key.
CsvParser.mapTo(Professor.class).addKeys("id", "students_id").stream(reader);
then the mapper will return 1 professor with 2 students.
0 : Professor1 { Students[ Student1, Student2 ] }
we are also able to identify null object on outer join. ie For the following row
id | name | students_id | students_name |
---|---|---|---|
1 | professor1 | null | null |
The mapper will now return a professor with an empty list of students instead of a student with null values.
0 : Professor1 { Students[ Student1 { id:null, name :null} ] }
vs
0 : Professor1 { Students[] }