tommysiu / beanio

Automatically exported from code.google.com/p/beanio
Apache License 2.0
0 stars 0 forks source link

Need a way to intercept format validation for ConfigurableTypeHandler #118

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Using BeanIO 2.1.0.M2

In order to parse some complicated fields I have been using the "format" 
attribute on the field to pass my ConfigurableTypeHandler the information it 
needs to do the parsing.  Unfortunately, in my best determination, BeanIO is 
taking the "format" attribute and using it for validation of the field outside 
of the control of the ConfigurableTypeHandler.  SO even though my code can 
correctly parse/format the data the 'Read' fails because (underlying validator) 
doesn't understand my custom format value.

Apologies if I'm missing an existing capability but it seems the full 
implementation of a ConfigurableTypeHandler would include the ability to code a 
custom validator for your ConfigurableType.  That or the ability to disable the 
validator (I'm fine with validating at parse-time instead of read-time) while 
still using the existing "format" attribute to get that information to 
newInstance.

This issue is related to my other issue 117 (As if I had the information 
requested in 117 then I wouldn't be trying to hack the contents of the format 
attribute) but both features seem like logical additions to the library 
regardless.

Thanks!

Original issue reported on code.google.com by omnipit...@gmail.com on 18 Aug 2014 at 4:09

GoogleCodeExporter commented 8 years ago
Hmm, "format" shouldn't be used outside of your own TypeHandler.  Can you 
pinpoint where that is happening?  Or share the custom type handler you wrote 
(or a simplified version that recreates the issue)?

Original comment by kevin.s...@gmail.com on 20 Aug 2014 at 4:05

GoogleCodeExporter commented 8 years ago
There's a lot going on in my type handler (and current version nuked this code 
because I had to find another way to make it work) but I've cleaned it up and 
re-coded in how I was doing it as reference.

The symptoms when BeanIO parses the file are that the Read of the record fails 
validation with the format explicitly specified in the error as "S000000000" 
where the format that is being passed to the handler is provably "000000000" so 
my only guess as to why the parser would even be aware of the original 
un-truncated form "S000000000" is that the format attribute is being read by 
other than my newInstance code.

Original comment by omnipit...@gmail.com on 20 Aug 2014 at 4:48

GoogleCodeExporter commented 8 years ago
It sounds like your type handler is not being properly registered, can you 
share your mapping file?

Original comment by kevin.s...@gmail.com on 26 Aug 2014 at 2:46

GoogleCodeExporter commented 8 years ago
I've attached the mapping (once again simplified but all the important bits are 
there).  I know the handler is being registered at least somewhat because 
logging I have in my handler is how I've been debugging this.  I may be missing 
some facet though... Thanks!

Original comment by omnipit...@gmail.com on 26 Aug 2014 at 3:44

GoogleCodeExporter commented 8 years ago
Can you attach a simple and complete example that recreates the issue?  

I can't make any sense of the code you've already posted for two reasons:
1.  You aren't setting a format attribute on the field in the mapping file, 
which I thought was your original issue.
2.  The TypeHandler you posted instantiates another TypeHandler implementation 
that you haven't shared.

Original comment by kevin.s...@gmail.com on 28 Aug 2014 at 3:07

GoogleCodeExporter commented 8 years ago
I've attached a modified version of the mapping with apologies that the format 
attribute got stripped. I've also attached the simple Bean to store the data as 
well as a file of sample data.

As for point 2: Which 'other' TypeHandler are you referring to?  Both 
TypeHandlers referenced in my TypeHandler (BigDecimalTypeHandler and 
ConfigurableTypeHandler) were written by you.

Original comment by omnipit...@gmail.com on 2 Sep 2014 at 10:33

Attachments:

GoogleCodeExporter commented 8 years ago
CustomFormatBigDecimalTypeHandler.newInstance() is creating a type handler 
called 'HardSignedBigDecimalMovablePointHandler', for which you have not 
included the source.  I would much prefer if you could provide a simpler 
implementation that recreates the issue.  Thanks!

Original comment by kevin.s...@gmail.com on 6 Sep 2014 at 2:34

GoogleCodeExporter commented 8 years ago
Fixed that for you...

Original comment by omnipit...@gmail.com on 8 Sep 2014 at 4:39

Attachments: