j-easy / easy-batch

The simple, stupid batch framework for Java
https://github.com/j-easy/easy-batch/wiki
MIT License
611 stars 199 forks source link

Keeping qualifier optional #35

Closed anandhi closed 9 years ago

anandhi commented 9 years ago

As of now, when mentioned the qualifier, it expects it to be present for all the fields, but there should be way to keep it optional. Use Case eg : product_id,product_title,product_price 100,"XYZ,MNP",201 200,"ABC KLP",501

and also As you see here, the enclosed column value("XYZ,MNP") has the delimeter as part of content, if the qualifier is mentioned, then delimeter which is present within the qualifier should be ignored.

fmbenhassine commented 9 years ago

Hi Anand, Thank you for pointing out this issue.

In fact, the built-in delimited-values mapper expects the qualifier to be present in all fields (as described in the user guide, section 4.1.1). Usually, input data is uniform (all fields are qualified or all fields are not qualified). Making the qualifier optional is not planned to be part of the built-in mapper, but I am planning to create an integration module with OpenCSV and SuperCSV for next release. I am not sure these libraries allow you to do it, do you know another java CSV parser that can do that?

In regards to the second point, please open a different issue since this is another problem (even though it is related to delimited values mapper). Thank you in advance.

Regards, Mahmoud

anandhi commented 9 years ago

Haven't tried the any other CSV parser than OpenCSV, But for now i am using regex to get these tokens. Something like this :
String[] tokens = recordRawContent.split(",(?=([^\"]\"[^\"]\")[^\"]$)");