Last active
September 27, 2019 08:57
-
-
Save arnaudroger/9c4c8dff984800faf061fa148b2b8186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.simpleflatmapper.csv.CsvMapper; | |
import org.simpleflatmapper.csv.CsvMapperFactory; | |
import org.simpleflatmapper.csv.CsvParser; | |
import org.simpleflatmapper.lightningcsv.CsvReader; | |
import java.io.IOException; | |
public class SampleReadingOneLine { | |
private static final CsvMapper<MyObject> mapper = | |
CsvMapperFactory | |
.newInstance() | |
.newBuilder(MyObject.class) | |
.addMapping("col1").addMapping("col2").mapper(); | |
public static void main(String[] args) throws IOException { | |
CsvReader reader = CsvParser.dsl().reader("val1,val2"); | |
MyObject next = mapper.iterator(reader).next(); | |
System.out.println("next = " + next); | |
} | |
public static class MyObject { | |
public final String col1; | |
public final String col2; | |
public MyObject(String col1, String col2) { | |
this.col1 = col1; | |
this.col2 = col2; | |
} | |
@Override | |
public String toString() { | |
return "MyObject{" + | |
"col1='" + col1 + '\'' + | |
", col2='" + col2 + '\'' + | |
'}'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment