1

init csv support

This commit is contained in:
Christoph
2020-03-16 13:56:05 +01:00
parent f4ad729efd
commit 9f464fe859
3 changed files with 31 additions and 4 deletions

View File

@ -0,0 +1,22 @@
package mops.gruppen2.service;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import mops.gruppen2.domain.User;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
public class CsvService {
public static List<User> read(InputStream stream) throws IOException {
CsvMapper mapper = new CsvMapper();
CsvSchema schema = mapper.schemaFor(User.class).withHeader().withColumnReordering(true);
ObjectReader reader = mapper.readerFor(User.class).with(schema);
return reader.<User>readValues(stream).readAll();
}
}