Skip to content

Support for collection fields #9

Description

@eximius313

I have a class:

public class Person {
    @CsvColumn(columnName = "name")
    private String name;
    
    @CsvColumn(columnName = "phones")
    private List<String> phones;
}

where phones could have 0...* elements;

I'd expect that such data (in JSON for readability):

[{ name: "Foo", phones: ["11"] }, { name: "Foo", phones: ["22", "23"] }, { name: "Foo", phones: [] }]

transformed by this code:

CsvProcessor<Person > csvProcessor = new CsvProcessor<>(Person .class);
File csvFile = new File("people.csv");
csvProcessor.writeAll(csvFile, list, true);

should output something like this:

name,phones/0,phones/1
Foo,11,
Foo,22,23
Foo,,

exactly like this tool https://konklone.io/json/ does it

but it throws:

java.lang.IllegalArgumentException: No converter available for type: interface java.util.List
	at com.j256.simplecsv.processor.ColumnInfo.fromAnnoation(ColumnInfo.java:242)
	at com.j256.simplecsv.processor.ColumnInfo.fromAnnotation(ColumnInfo.java:219)
	at com.j256.simplecsv.processor.CsvProcessor.addColumnInfo(CsvProcessor.java:1183)
	at com.j256.simplecsv.processor.CsvProcessor.configureEntityClass(CsvProcessor.java:1017)
	at com.j256.simplecsv.processor.CsvProcessor.checkEntityConfig(CsvProcessor.java:997)
	at com.j256.simplecsv.processor.CsvProcessor.writeAll(CsvProcessor.java:414)
	at com.j256.simplecsv.processor.CsvProcessor.writeAll(CsvProcessor.java:398)

Could you please support collections in SimpleCSV?
One solution is that @CsvColumn could have boolean parameter collectionValues (because names can be generated using name as a base)

Kind regards

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions