Share

opencsv

Tracker: Support Requests

5 Working with dates in CsvToBean - ID: 2882605
Last Update: Comment added ( sconway )

Using the bean function to map the fields, I was hoping there would be some
example on how to work with dates.

My csv file date looks like this: 12-Jan-2009 00:00:00

My bean class has a field java.sql.Timestamp

When I do the List<App_request_extract> list = csv.parse(strat, reader); I
get an error that it could not map the value. I removed the date from the
extract and the bean, then the csv.parse worked beautifully.

I am probably missing something obvious. Do I have to override a method or
set something in the Mapping Strategy?


CSVReader reader = new CSVReader(new BufferedReader(new
FileReader("extract.csv")), '|', CSVWriter.NO_QUOTE_CHARACTER);

HeaderColumnNameMappingStrategy<App_request_extract> strat = new
HeaderColumnNameMappingStrategy<App_request_extract>();
strat.setType(App_request_extract.class);

CsvToBean<App_request_extract> csv = new
CsvToBean<App_request_extract>();
List<App_request_extract> list = csv.parse(strat, reader);


trames ( trames ) - 2009-10-20 19:21

5

Closed

None

Nobody/Anonymous

None

None

Public


Comments ( 3 )

Date: 2009-12-10 12:59
Sender: sconway

Added Feature request 2911984 which is a more generic version of 2892681
that will hopefully take care of this when implemented.



Date: 2009-10-27 21:00
Sender: trames

Sure.
Attached is a runnable class that includes app_request_extract
Attached is a small csv file with sample data


Date: 2009-10-21 13:53
Sender: sconway

Could you please attach the following.

1. A small csv file with one or two records with the data that causes the
issue.
2. app_request_extract.java
3. A small runnable app that recreates the issue

Given the code you put in the issue I can recreate #3 easily enough but 1
and 2 would REALLY be helpful.


Attached Files ( 2 )

Filename Description Download
TestExtract.java runnable class Download
lawson_extract.csv csv test data Download

Changes ( 5 )

Field Old Value Date By
close_date - 2009-12-10 12:59 sconway
allow_comments 1 2009-12-10 12:59 sconway
status_id Open 2009-12-10 12:59 sconway
File Added 348445: lawson_extract.csv 2009-10-27 21:02 trames
File Added 348444: TestExtract.java 2009-10-27 21:01 trames