0 Replies Latest reply on Sep 4, 2013 8:11 AM by coelho_extremo

    Jsefa - CSV

    coelho_extremo

      Hi all... I need read a CSV file and deserialize it in java objects.

      I found this project : https://github.com/oasits/JSefa

      Reading the docs and samples in project, I trying use this ideia to my case. this is my file:

       

      |0000|departament1||

      |0001|jones|ruberval|

      |0001|usnave|capirot|

       

      and my models:

      Department.java

      @CsvDataType(defaultPrefix="0000")
      public class Department {
        
           @CsvField(pos = 0)
           String name;
        
          @CsvSubRecordList(pos = 1, records = @Record(prefix = "0001"))
          List<Employee> employees;
      
      }
      

      Employee.java

      @CsvDataType(defaultPrefix="0001")
      public class Employee {
        
          @CsvField(pos = 0)
          String name1;
      
          @CsvField(pos = 1)
          String name2;
      
      }
      

       

      Method to deserializer...

       

      CsvConfiguration csvConfiguration = new CsvConfiguration();
      csvConfiguration.setFieldDelimiter((char) 124);
      
      Deserializer deserializer = CsvIOFactory.createFactory(csvConfiguration,Department.class).createDeserializer();
      deserializer.open(textReader);
      
      while (deserializer.hasNext()) {
          Department parent = deserializer.next();
          System.out.println(parent);
      }
      deserializer.close(true);
      

       

      The Problem...

      In my layout, the field to define a line type, is a second position, and not a first...

      I read API docs but... not found configuration for this case..

      Someone can help me? thanks...