unlockha / beanio

Automatically exported from code.google.com/p/beanio
Apache License 2.0
1 stars 0 forks source link

Groups and records not required. #91

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

I am Trying deserealize CSV file to java Objects.
This is my CSV file:

|0000|departament 1
|0001|joao1
|0002|car
|0001|joao2
|0002|bike
|0000|departament 2
|0001|joao3
|0001|joao4
|0002|nave

this is my stream:

 <stream name="departaments" format="csv">
      <parser>
         <property name="delimiter" value="|" />
         <property name="multilineEnabled" value="true" />
      </parser>
      <group name="departments" class="test.com.example.model.Department">
         <record name="department" order="1">
            <field name="type" rid="true" at="1" literal="0000" ignore="true" />
            <field name="name" at="2" />
         </record>
         <group name="employees" order="2" collection="list" class="test.example.model.Employee">
             <record name="emp" order="1">
                <field name="type" rid="true" at="1" literal="0001" ignore="true" />
                <field name="name" at="2" />
             </record>
             <record name="transports" order="2" collection="list" class="test.example.model.Transport">
                <field name="type" rid="true" at="1" literal="0002" ignore="true" />
                <field name="name" at="2" />
             </record>
         </group>
      </group>
   </stream>

My classes:
public class Department {
    String name;
    List<Employee> employees;
}

public class Employee {
    String name;
    Department dep;
    List<Transport> transports;
}

public class Transport {
    String name;
}

I expected:

The Size of list Employees in Department 1 = 2
The Size of list Employees in Department 2 = 2

I see instead:
The Size of list Employees in Department 1 = 2
The Size of list Employees in Department 2 = 1

Class transport, not required.

Version 2.1.0-M1
JDK 1.6

Original issue reported on code.google.com by coe...@extremosistemas.com.br on 12 Sep 2013 at 3:33

GoogleCodeExporter commented 8 years ago
Sorry for the delayed response, but you need to set occurs="1" on the "emp" 
record to trigger a new Employee object to be read, otherwise subsequent 
records will overwrite the first one if a transport record does not exist.

Thanks,
Kevin

Original comment by kevin.s...@gmail.com on 21 Sep 2013 at 2:17