How to read dynamic field length in .csv using Spring Batch?

Viewed 212

I have a csv with the following content:

id001 , mail1@test.de  , mail2@test.de
id002 , mailxx@test.de , mailxx@test.de , mailxx@test.de, mailxx@test.de...

The csv has no static mail fields the list contains dynamically created mail addresses, is it possible to parse these in an array with spring batch?

1 Answers

You can use a custom LineMapper for that. This interface gives you the raw string that was read from the file and allows you to parse it and map it to your domain object.

You did not share your target type, but I think a line.split(","); could work in your case: you assign the first token to an id and the remaining tokens to a list of emails.

Related