super-csv / super-csv

A fast, programmer-friendly, free CSV library for Java
http://super-csv.github.io/super-csv
Apache License 2.0
527 stars 140 forks source link

Issue due to quote and the delimiter #72

Closed WalsonRene closed 8 years ago

WalsonRene commented 9 years ago

Hello!

I have a big problem that i cant resolve i search evrywhere but i can't found a solution.

my processors

  private static CellProcessor[] getProcessors() {

    //CUSTOMER_CD (must be unique)  customerName CFM_REPORTING_REGION_CD
    final CellProcessor[] processors = new CellProcessor[] {new UniqueHashCode(),  new NotNull(),  new NotNull()};
    return processors;
}

my readWithCsvBeanReader

public static void readWithCsvBeanReader() throws Exception {

    ICsvBeanReader beanReader = null;

    try {

        beanReader = new CsvBeanReader(new FileReader(CSV_FILENAME), CsvPreference.STANDARD_PREFERENCE);
        // the header elements are used to map the values to the bean (names must match)
        String[] header = formatHeaders(beanReader.getHeader(true));

        //final String[] header = beanReader.getHeader(true);
        final CellProcessor[] processors = getProcessors();

        IfsCustomerDataBean oneIfsCustomerData;
        while( (oneIfsCustomerData = beanReader.read(IfsCustomerDataBean.class, header, processors)) != null ) { //Record CSV Data to bean (object)
            System.out.println(String.format("lineNo=%s, rowNo=%s, customer=%s", beanReader.getLineNumber(), beanReader.getRowNumber(), oneIfsCustomerData));
        }   
    }
    finally {
        if( beanReader != null ) {
            beanReader.close();
        }
    }
}

and my csv file 10 first line

CUSTOMER_CD,CUSTOMER_NAME,CFM_REPORTING_REGION_CD ARA,ARIK AIR LIMITED,SA
RBB,"RABBIT-AIR AG, ZURICH",SA
LUXF,LUXFLIGHT,SA
ISDA,ISD AVIA LTD,SA
KEAI,KEY AIR INC,INC
NMB,AIR NAMIBIA,SA
AVAI,AVAIR,INC
OPER,OPERADORA TURISTICA AURORA S.A.,INC
ALGA,ALG AERO-LEASING,INC

My problem is when i run

lineNo=2, rowNo=2, customer=IfsCustomerDataBean [CUSTOMER_CD=ARA, CUSTOMER_NAME=ARIK AIR LIMITED, CFM_REPORTING_REGION_CD=SA ;, LINE_NUMBER=1] Exception in thread "main" java.lang.IllegalArgumentException: the nameMapping array and the number of columns read should be the same size (nameMapping length = 3, columns = 1) at org.supercsv.io.CsvBeanReader.readIntoBean(CsvBeanReader.java:251) at org.supercsv.io.CsvBeanReader.read(CsvBeanReader.java:190) at com.snecma.csv.controller.v1.controller.Reading.readWithCsvBeanReader(Reading.java:86) at com.snecma.csv.controller.v1.main.Main.main(Main.java:12)

WalsonRene commented 9 years ago

Please i realy need your help; I try the method readWithCsvListReader. but i have this errors

lineNo=2, rowNo=2, customerList=[ARA, ARIK AIR LIMITED, SA ;] Exception in thread "main" org.supercsv.exception.SuperCsvException: The number of columns to be processed (1) must match the number of CellProcessors (3): check that the number of CellProcessors you have defined matches the expected number of columns being read/written context={lineNo=3, rowNo=3, columnNo=1, rowSource=[RBB,"RABBIT-AIR AG"," ZURICH",SA ;]} at org.supercsv.util.Util.executeCellProcessors(Util.java:78) at org.supercsv.io.AbstractCsvReader.executeProcessors(AbstractCsvReader.java:203) at org.supercsv.io.CsvListReader.executeProcessors(CsvListReader.java:96) at org.supercsv.io.CsvListReader.read(CsvListReader.java:86) at com.snecma.csv.controller.v1.controller.Reading.readWithCsvListReader(Reading.java:107) at com.snecma.csv.controller.v1.main.Main.main(Main.java:12)

WalsonRene commented 9 years ago

Someone can help me please ?

kbilsted commented 9 years ago

Hi @WalsonRene you are showing two different errors for the same code example?

How does the example work found at http://super-csv.github.io/super-csv/examples_reading.html ?

ZioberMichal commented 8 years ago

Hi @WalsonRene, do you still need a help with this?

ash211 commented 8 years ago

Given that we haven't heard from @WalsonRene in 6 months now I'd move to close this ticket.