Replies: 1 comment 1 reply
-
I think adding a custom type handler class for this makes better sense? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have a file which I parse into a record using beanio. Some of the fields in the file represent date strings in the form of yyyyMMdd (20230720), however some dates can be optional and are marked as 00000000 in the file. When using a format on the field, this will result in an InvalidRecordException (with an underlying DateTimeParseException).
I am looking for a way to check the DateTimeParseException and if the exception text contains 00000000, I want to leave the field null and in all other cases rethrow the original InvalidRecordException.
Let's say I have a MyRecord cIass containing a LocalDate field of which the value is 00000000:
I am able to set an exception handler on the beanReader as such:
The
optionalDateExceptionHandler
contains the logic of checking the InvalidRecordException and if it contains a DateTimeParseException with a value of 00000000. This works fine.However, I cannot figure out how to set the date field to null (and ignore the exception) so the rest of the record can be parsed.
Is this possible at all? What I notice now is that when the exception occurrs, I can do something with the exception, but the entire record is skipped.
Beta Was this translation helpful? Give feedback.
All reactions