Skip to content
Advertisement

UNIVOCITY-PARSERS for csv to bean object stopping as soon as error has occured

I’m using UNIVOCITY-PARSERS for converting csv file rows into java objects.

while processing the file, if it encounters any problem any of the column in row, then it parsing getting stopped in that row and throwing exception. But i need something which will continue till end of the file just by skipping the row which has error. But i didn’t any utility classes in the api.

MY Bean class

JavaScript

My Main Class

JavaScript

Advertisement

Answer

Just use an error handler and it will keep going unless you throw the exception yourself:

JavaScript

UPDATE: You can prevent the row to be discarded by using a RetryableErrorHandler instead. This is a special implementation added to version 2.3.0, and allows the user to call the methods setDefaultValue() to assign a value to the problematic column, and keepRecord to prevent the record from being discarded.

Example:

JavaScript

Note that if error.getColumnIndex() returns -1, there’s nothing that can be done to save the record, and it will be skipped regardless. You can use this to log the error details.

Advertisement