I am using Univocity's CSVParser to read csv file. My POJO look something like this.
import java.time.LocalDate;
import com.univocity.parsers.annotations.NullString;
import com.univocity.parsers.annotations.Parsed;
import lombok.Builder;
import lombok.Getter;
@Getter
@Setter
public class TempClass {
@Parsed(field = "A")
private int a;
@Parsed(field = "B")
private String b;
@Parsed(field = "C")
private LocalDate c;
}
My csv file look something like this:-
A,B,C
1,"Hi","2019-01-12"
2,"Hey","2019-01-13"
3,"Hello","2019-01-14"
Now when I try to read this file using CsvParser, it throws error saying Unable to set value '2019-01-12' of type 'java.lang.String' to field attribute 'c'
.
Here I am guessing it is throwing error because it can not implicitly convert String
to LocalDate
. If that is the case then How can it able to convert String
to int
?
Is there way to solve the error Unable to set value '2019-01-12' of type 'java.lang.String' to field attribute 'c'
?(without changeing data type of TempClass.c
)