return EngineType.get(String.valueOf(chars));
}).newBuilder(PlaneInfo.class)
.addMapping("id")
.addMapping("manufacturer")
.addMapping("model")
.addMapping("engineType")
.addMapping("year")
.mapper();
CsvParser.skip(1)
.mapWith(mapper)
.stream(source)
.forEach(p -> System.out.println(p));
This seems to work but I would love to know if there is an easier way to do this.
Thanks in advance for your help!
-Tony
return EngineType.get(String.valueOf(chars, offset, length));
}).newBuilder(PlaneInfo.class)
.addMapping("id")
.addMapping("manufacturer")
.addMapping("model")
.addMapping("engineType")
.addMapping("year")
.mapper();
.newMapper(PlaneInfo.class);
CsvParser.mapWith(mapper)
.stream(source)
.forEach(p -> System.out.println(p));
avoiding all the addMapping. note that also the mapper is thread safe and if you will use it multiple time you can reuse the same over and over again
reducing the cost of mapper generation.
to make things simpler I might add a
addCustomValueReader(String key, Function<String, ?> reader) that would give you
CsvMapper<Plane> mapper =
.newMapper(PlaneInfo.class);
that would be relatively straightforward
CsvParser.skip(1)
.filter(s -> s.length > 10) // this would ignore lines that are too short
.mapWith(mapper)
.stream(source)
.forEach(p -> System.out.println(p));
CsvParser.skip(1)
.filter(s -> s.length() > 10) // prev post was missing the parens after s.length
.mapWith(mapper)
.stream(source)
.forEach(p -> System.out.println(p));