Open clamothe opened 6 years ago
Thanks for the bug report. I’ll need to look deeper into that one. It must be possible to have different default formatter by type.
You can also specify date formatter per column. I’ll find the code later
Great, I appreciate your responsiveness.
so thinking about it, also that would be great to have a different default pattern per type i'm afraid that change my have some backward compatibility issue.
so otherwise to have the datetimeformat at the column level
CsvMapperFactory
.newInstance()
.addColumnProperty("date_column", new DateFormatProperty("yyyy-MM-dd"))
.newMapper(CociProgram.class)
.stream(reader);
the first a Predicate
CsvMapperFactory
.newInstance()
.addColumnProperty(k -> k.getName().startsWith("date"), new DateFormatProperty("yyyy-MM-dd"))
.newMapper(CociProgram.class)
.stream(reader);
I'll keep the ticket open to update the documentation.
Thanks! I'll use the field-specific solution for now. It is true that someone may expect different behavior than I, or existing code depends on this functionality. One could desire to parse a Date+time string into a LocalDate, though ideally that would be not be the primary supported case.
I wonder if the default date time format could be modified to optionally expect time. That could still could have backwards compatibility issues in some edge cases.
updated doc
just read the last comment and yes could have something that check if have time
This results in the following exception:
By default, a date format of ""yyyy-MM-dd HH:mm:ss" is used, even for parsing LocalDates. This is defined in CsvMapperBuilder::defaultDateFormat and does not differ per Date field type.
The tests written for CharSequenceToLocalDateConverter test it with a "yyyy-MM-dd" format. CSV parse should expect this format by default for the LocalDate field.
I was able to work around this using, however overriding the default date format isn't a solution if I also want to parse LocalDateTime fields.
Does this look like a bug? Is there a better workaround? Thanks! Cool library