I'm asking advice for a csv deserialization librar...
# getting-started
p
I'm asking advice for a csv deserialization library. I think the following things are important for me: • handles large csv files (outputs ~List~SequenceMyObject, does not store all rows in memory) • handles header row to address columns by "name" • target is JVM • support for null values
r
I've had good experiences with: https://github.com/jsoizo/kotlin-csv It supports headers, and reading the csv line by line, using either a
Sequence
or custom code
p
The list of open issues / pull requests frightens me. Specially this is unanswered: https://github.com/jsoizo/kotlin-csv/issues/161
And what about null value handling?
r
I think that issue is unanswered because the readme already shows how to return a sequence 😅 And regarding null values: if you read the csv with headers, every row is a map where the keys are the column names, so that should work 🙂
😅 1
f
I'm using
com.opencsv:opencsv
on this open source project, it's pretty easy to use, I don't know if this is what you're looking for https://github.com/openflocon/Flocon/blob/6bcfbf8e0989e8176eedbb6afccae71234bca44b[…]/io/github/openflocon/data/local/network/utils/ImportFromCsv.kt
j
We're using this one at work (also for files that don't fit in memory and with headers, JVM): https://commons.apache.org/proper/commons-csv/ Not sure what you need regarding the null values.
j
As this is in #C0B8MA7FA - maybe its worth highlighting the difference between List and Sequence - in your criteria, you said that it must be a List, but also that it must not store all items in memory. You probably want a Sequence, not a List.
k
I agree with James that Sequence is the idiomatic thing to use here. However, there are "lazy list" implementations out there (e.g. in Apache Commons Collections) where a list item is fetched on demand.
p
@James Richardson,sorry, a typo in my requirements, I definitely need sequence
j
yeah - i presumed so. no big deal, it was just in case other people also getting started might be confused.
p
Regarding null values:
The first column should be empty, the second should be null
k
> The first column should be empty, the second should be null Given that CSV cells typically aren't enclosed in quotes, why wouldn't the second column be empty? Quotation marks are typically used when the cell contains a comma, but I've never heard of them being used to distinguish between empty and null.