При синтаксическом анализе CSV с пользовательским разделителем столбцов ';'и используя:
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
я получаю следующую ошибку:
com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class Author] from String value ('Email;FirstName;LastName'); no single-String constructor/factory method
вот мой код синтаксического анализа:
public static <T> List<T> loadObjectList(Class<T> type, String fileName) {
CsvSchema bootstrapSchema = CsvSchema.emptySchema();
bootstrapSchema.withColumnSeparator(';').withoutQuoteChar();
CsvMapper mapper = new CsvMapper();
File file = new File(fileName);
MappingIterator<T> readValues =
mapper.reader(type)
.with(bootstrapSchema)
.readValues(new InputStreamReader(new FileInputStream(file), "ISO-8859-1"));
return readValues.readAll();
}
и вот моя модель, я хочусопоставить с CSV:
@JsonPropertyOrder({ "Email", "FirstName", "LastName" })
public class Author {
String Email;
String FirstName;
String LastName;
public String getEmail() {
return Email;
}
public void setEmail(String Email) {
this.Email = Email;
}
public String getFirstName() {
return FirstName;
}
public void setFirstName(String firstName) {
FirstName = firstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String lastName) {
LastName = lastName;
}
public Author(String email, String firstName, String lastName) {
Email = email;
FirstName = firstName;
LastName = lastName;
}
}