Reputation: 15620
I am building a generic tool in Java which reads data from a CSV and assigns it to some variables in the code and does bunch of stuff with it. I just realised that I should use an existing library (like SuperCSV) than doing it on my own. Now my question is the following: Since this is a generic tool, the datatypes of the values are not known. It depends what is present in the CSVfile. Now the user who would be building the CSV would know the datatypes. So I could add a "datatype" column in the CSV and the user could write "int" or "float" or "String" there. And then I could use if/then clauses in the code to assign the right datatype. But I am not sure if that is the most apt approach. Any thoughts? (I dont post on StackOverflow often so please advise if I am not being clear or detailed enough. Thanks!)
regards Anupam
Upvotes: 0
Views: 994
Reputation: 59
This does not look too effective to pratically define data type before each data item in a CSV-like data processing. I would suggest to ask the CSV creator to specify the data types of each column beforehand in a predefined manner (say, specify a separate one-line CSV file with each data type, cause I think mixing raw data with metadata is not a good idea in this case). In my experience there was a similar task to process several types measurement tool data and raw data CSV files were as-is, metadata was specified in XML, but was not processed with each file.
Upvotes: 1