@Test
public void testIgnoreFailedMapRow() throws IOException {
CsvMapper<AB> csvMapper = CsvMapperFactory
.newInstance()
.fieldMapperErrorHandler((key, source, target, error) -> {
System.out.println("error : " + key + "," + source + "," + target +"," + error);
})
.newMapper(AB.class);
CsvParser.mapWith(csvMapper).stream("a,b\n1,2\nfreddy is coming for you\n3,4\nbetter lock your door").forEach(r-> System.out.println("row = " +r));
}
public static class AB {
public final int a;
public final int b;
public AB(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public String toString() {
return "AB{" +
"a=" + a +
", b=" + b +
'}';
}
}
Thanks for the fast reply! Here is an example of a data file where I would like to ignore the rows that have lots of missing fields:
+1 for adding the feature to allow ignoring rows with parse errors.
Thanks for your work on this very useful library.
-Tony