Im using univocity for parsing csv file. But I cant parse date in String format to java.util.Date. It seems like the @Format(formats ="YYYY-MM-DD") annotation is not working.
Im trying parse line
2015-04-30,67,"P",1972-02-28,2006-08-11,"97912a4321dd510","49d180ecf56132819571bf39d9b7b34"
but it gives me this format after parsing, which is not YYYY-MM-DD. Can you help me?
day=Sun Dec 28 00:00:00 CET 2014, id=5151, type=B, originDate=Sun Dec 31 00:00:00 CET 1950, relDate=Sun Dec 26 00:00:00 CET 2010, legalId=3bbfca2849c01ad, name=236e5fcfd21603c33b82ddd89bab7c4
My model class:
import java.util.Date;
import com.univocity.parsers.annotations.Format;
import com.univocity.parsers.annotations.Parsed;
public class Customer {
@Format(formats ="YYYY-MM-DD")
@Parsed(field="C_DAY")
private Date day;
@Parsed(field="C_ID")
private Integer id;
@Parsed(field="C_TYPE")
private Character type;
@Format(formats ="YYYY-MM-DD")
@Parsed(field="C_ORIGIN_DATE")
private Date originDate;
@Format(formats ="YYYY-MM-DD")
@Parsed(field="C_REL_DATE")
private Date relDate;
@Parsed(field="C_LEGAL_ID")
private String legalId;
@Parsed(field="C_NAME")
private String name;
Testing output with method:
public void parse(File file) throws IOException {
CsvParserSettings parserSettings = new CsvParserSettings();
parserSettings.getFormat().setLineSeparator("\n");
parserSettings.setHeaderExtractionEnabled(true);
CsvRoutines routines = new CsvRoutines(parserSettings);
for (Customer customer : routines.iterate(Customer.class, file, "UTF-8")) {
System.out.println(customer);
}
}