I wanted to know if there is a way to check and validate a field when using the CsvRoutines package. Basically I want to process a row if the first column has only numbers and skip/possibly throw an exception otherwise. I'm guessing @Validate annotation released in 2.7.0 can be used to achieve this. But I would like to know if there is any other way to achieve the same with earlier versions like 2.5.9?
Validate parsed fields using Univocity Parser
711 views Asked by user2220232 At
1
Author of the library here. There's no other way other than updating to the latest version. Is there any reason in particular why you can't upgrade?
Update: you can put the
@Parsedannotations on the class' getters or setters and perform the validations in them. That is probably the cleanest way to go about it. For example:Another alternative is to use a custom conversion class. Copy the code of class ValidatedConversion, used in the newest version, then create subclass like:
Now on your code, use this:
I didn't test this against an old version. I think you may need to set flag
applyDefaultConversion=falsein the@Parsedannotation, and make your conversion class convert aStringinto anintin addition to run the validations.All in all, that's quite a bit of work that can easily be avoided just by upgrading to the latest version.