Trimming spaces from input number fields

178 views
Skip to first unread message

Paolo Lim

unread,
Aug 27, 2012, 4:42:29 PM8/27/12
to bea...@googlegroups.com
Hello!

I wasn't sure whether this was a bug or if there is something I am doing wrong.  I posted this same thing as a bug in: http://code.google.com/p/beanio/issues/detail?id=40.  Sorry if this is a duplication of the issue.

Here is the mapping file I am using:
  <stream name="blahblah" format="csv">
    <parser>
      <property name="delimiter" value="|" />
    </parser>
    <record name="foobar" minOccurs="1" maxOccurs="unbounded" class="blah">
      <field name="someNumber" type="java.lang.Long" format="#0" />
      <field name="somethingElse" />
    </record> 
  </stream>
</beanio>

Here is the input:
156000033 |Hello World

And this is the exception I am seeing:
Invalid 'someNumber': Type conversion error: Invalid Long value '156000033 '
at org.beanio.internal.parser.UnmarshallingContext.validate(UnmarshallingContext.java:196)
at org.beanio.internal.parser.BeanReaderImpl.internalRead(BeanReaderImpl.java:105)
at org.beanio.internal.parser.BeanReaderImpl.read(BeanReaderImpl.java:64)
at org.apache.camel.dataformat.beanio.BeanIODataFormat.readModels(BeanIODataFormat.java:148)
at org.apache.camel.dataformat.beanio.BeanIODataFormat.unmarshal(BeanIODataFormat.java:110)
....

If I pass in a format pattern to the field, shouldn't it parse correctly in NumberTypeHandler?  I get this in Java 1.6 and BeanIO 2.0.1.

Thanks!
Paolo

Kevin

unread,
Aug 29, 2012, 11:22:48 AM8/29/12
to bea...@googlegroups.com
Hi Paolo,

You'll need to download the 2.0.2 snapshot jar from issue #38 and set trim="true" on any field where you need to trim spaces before type conversion.

Thanks,
Kevin

Paolo Lim

unread,
Aug 29, 2012, 11:29:48 AM8/29/12
to bea...@googlegroups.com
Thanks, Kevin.

I didn't realize that #38 was the same issue since it seems that they were using Strings and mine was a Long/Integer.  Any idea when BeanIO 2.0.2 would be released?

Paolo

Kevin

unread,
Aug 29, 2012, 7:14:02 PM8/29/12
to bea...@googlegroups.com
Hi Paolo,

Trim applies to all data types.  I'll probably create a 2.0.2 release sometime in September.  The snapshot jar is stable if you need something sooner.

Thanks,
Kevin
Reply all
Reply to author
Forward
0 new messages