davidsantiago / clojure-csv

A library for reading and writing CSV files from Clojure
187 stars 35 forks source link

nil cells cause NPE #22

Closed jasonab closed 11 years ago

jasonab commented 11 years ago

Given a sequence that contains nil entries, needs-quote? throws NullPointerException:

java.lang.NullPointerException: null core.clj:228 clojure-csv.core/needs-quote? core.clj:244 clojure-csv.core/quote-and-escape core.clj:255 clojure-csv.core/quote-and-escape-row[fn]

davidsantiago commented 11 years ago

I don't consider this an error, actually. Clojure-CSV is not in the business of serializing your objects; write-csv expects a sequence of strings for a row, not strings, numbers, nils, and anything else, that it must then have an opinion on how to write in the CSV file.

What you should do is write a function that you can map on your rows, and turn any nil entries into "" or "nil" or whatever you wish to happen with nil entries.

simonbronner commented 9 years ago

Agree with the sentiment, but in practice, every user if the library will end up writing a nil conversion function. fwiw, I tend to think it would be a good idea for this feature to be implemented, if only for the pragmatic reason of saving a little effort on behalf of 1000's of happy nil passing users.