我正在使用 Univocity 的 CSVParser 来读取 csv 文件。我的 POJO 看起来像这样。
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;
}
我的 csv 文件看起来像这样:-
A,B,C
1,"Hi","2019-01-12"
2,"Hey","2019-01-13"
3,"Hello","2019-01-14"
现在,当我尝试使用 CsvParser 读取此文件时,它会抛出错误说Unable to set value '2019-01-12' of type 'java.lang.String' to field attribute 'c'
.
在这里我猜它会抛出错误,因为它不能隐式转换String
为LocalDate
. 如果是这种情况,那么它如何能够转换String
为int
?
有没有办法解决这个错误Unable to set value '2019-01-12' of type 'java.lang.String' to field attribute 'c'
?(不改变数据类型TempClass.c
)