1
@Parsed(field="ABC")
@Format(formats="yyyy-MM-dd HH:mm:ss.SSSSSSSSS")
private LocalDateTime abcDateTime;

Is above supported in Univocity Parsing ? using 2.8.1 version

Rakesh
  • 235
  • 2
  • 10

1 Answers1

3

Univocity-parsers is still built on Java 6. LocalDate is not directly supported out of the box, but can to provide a conversion yourself. Something like:

public class LocalDateFormatter implements  Conversion<String, LocalDate> {

    private DateTimeFormatter formatter;

    public LocalDateFormatter(String... args) {
        String pattern = "dd MM yyyy";
        if(args.length > 0){
            pattern = args[0];
        }
        this.formatter = DateTimeFormatter.ofPattern(pattern);
    }

    @Override
    public LocalDate execute(String input) {
        return LocalDate.parse(input, formatter);
    }

    @Override
    public String revert(LocalDate input) {
        return formatter.format(input);
    }
}

Then annotate your fields with @Convert and provide your conversion class:"

@Parsed(field = "C")
@Convert(conversionClass = LocalDateFormatter.class, args = "yyyy-MM-dd HH:mm:ss.SSSSSSSSS")
private LocalDate abcDateTime;

The next version (3.0.0) is coming soon with support for this and a lot more.

Hope this helps.

Jeronimo Backes
  • 6,141
  • 2
  • 25
  • 29