Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Row identifier for CSV errorMappingField #517
Is there a way to identify which row a field mapping error occurred for?
I need to display validation errors in my UI if a CSV is not parsable due to field-level errors.
That said, it would be great to be able to define the desired types directly on the CSV model (LocalDate, various Enums, etc). If I do so however, I cannot currently catch conversion errors in such a way that both the column and row in error are identified.
Ideally all errors in a particular row would be caught in the first run too, as opposed to short-circuiting parsing of a row once the first field error is encountered. This may be current functionality, I'm not certain.
Thanks for the idea, I need to think about it. when we parse the csv it does not have the visibility on the full line, but just see cell by cell. Though we could pass a partially constructed object or the list a constructor args currently build - for constructor injected object, as the information is there in the parser.
I'm accomplishing validation now by having a very permissive CSV model, with all String fields. It has Hibernate Validator annotations on it. If it passes validation, then I convert it to a different class that has more specific types (i.e. LocalDate instead of String). This solution feels good enough to me.
added a commit
Jun 9, 2018
so I've been thinking about it and I came with that prototype
where basically the mapper will not map to the object directly but to a wrapper that will collect the error that occurs during the parsing.
that would be added to the mapper factory as a one call - name undefined now. but would work as in the test.