csv

Java Annotation based CSV serialization/deserialization tool.It provide batch style api for small scale data, also, provide streaming style api for large scale data.

# 这是一个根据Java Class Field进行CSV序列化/反序列化的工具,基于注解的形式,只需要在相关类上添加注解,就可以实现自定义的CSV序列化/反序列化方案

通过调用CsvSerializer.serialize(*)来进行CSV序列化

相关注解:

Demo:

@CsvIgnoreProperties({"country"})    
public class Address {

    private String country = "CN";

    @CsvIgnore
    public String state = "ZJ";

    private String city = "Hangzhou";

}

public class Person {

    @CsvProperty(header="Name", order=1)
    private String name = "Lahahana";

    @CsvProperty(header="ID", order=0)
    private int id = 10001;

    @CsvProperty(header = "Birthday", order=2, convertor = TimeToDateConvertor.class)
    public long birthday= System.currentTimeMillis();

    private Address address = new Address();

    public static void main(String []args) throws CsvException, IOException {
        List persons = new ArrayList();
        Person person = new Person();
        for(int i=0;i<10;i++)
            list.add(person);    
        FileWriter out = new FileWriter("result.csv");
        CsvSerializer serializer = new CsvSerializer.Builder(out).build();
        serializer.serialize(persons, Person.class);
        serializer.close();
    }
}

Result:
ID,Name,Birthday,city
10001,Lahahana,Tue Mar 28 21:14:59 GMT+08:00 2017,Hangzhou
10001,Lahahana,Tue Mar 28 21:14:59 GMT+08:00 2017,Hangzhou

Maven Dependency:

    <dependency>  
        <groupId>com.github.lahahana</groupId>  
        <artifactId>csv</artifactId>  
        <version>2.0.1</version>  
    </dependency>