jeudi 28 mars 2019

How to convert multiple different .csv files with different headers?

Could you help me to figure out the best solution for my task?

I'm reading multiple .csv files and persist the data in a certain table into db.

The table is pretty straightforward and has such columns as first_name, last_name, birth_date

The data in ingress .csv files are also almost similar to each other but first_name header could be represented as first_name, firstName, First Name, etc. Also, the birth_date can be provided in various formats: it can be as yyyy-MM-dd HH:mm:ss:SSS ZZZZZ as dd-MM-yyyy.

My Brute Force approach is to create a mapper for each possible set of headers that would be invoked based on the headers and maps the .csv file to the List of entities. However, it doesn't seem good because it's not extendable at all to create a new mapper per each possible format.

One more requirement that I have is that information should be configurable via external configuration files. It makes me struggle.

Could you advise a good solution to my problem?

Aucun commentaire:

Enregistrer un commentaire