0

I recently upgraded my BeanIO framework to 2.0.6 version to parse my flat (tab delimited) files to java objects and I noticed so weird behavior. I can't leave fields null in the last file line at the end because BeanIO throws this error message at me: "Expected minimum 1 occurrences."

I tried to even set the maxLength to 4 on the entire record so that it account for the extra null field at the end but it still throws that exception. What's strange is that it only does it for the last line and not for null fields in the other lines.

Mapping:

<beanio xmlns="http://www.beanio.org/2012/03" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">
  <stream name="Inventory" format="delimited" strict="true" resourceBundle="com.crunchtime.mapping.cdp.Inventory">
    <record name="myRecord" minOccurs="1" maxOccurs="unbounded" minLength="0" maxLength="4" class="com.test.Record">
      <field name="userName" type="string"/>
      <field name="userId" type="string"/>
      <field name="type" type="string"/>
      <field name="version" type="string"/>
    </record>
  </stream>
</beanio>

File:

Mark    User1   M   1.0
Tom User2   D   1.1
Jim User3   M   2.0
Scott   User4   G   

Does anybody has any ideas on how to disable that behavior? I looked at beanio.properties but I can't modify since it's locked.

goe
  • 343
  • 1
  • 4
  • 13

1 Answers1

4

Using BeanIO 2.0 or later, you must configure fields that may not be present in the input stream with minOccurs="0".

Kevin
  • 76
  • 1
  • well yes that would fix it but what I don't understand is why this happens only to the last line and why a null value in an otherwise properly define field (I do have a tab for it) constitutes a "not present field". Do you know if there's a good way to overwrite the default beanio.properties file and its org.beanio.field.minOccurs.delimited=1 setting? I get BeanIO via Maven so I can modify beanio.properties but I can really check it in as part of my project. Is there a way to still get the jar from maven but tell the StreamFactory.class to use my local beanio.properties file somehow? – goe Aug 07 '13 at 13:38
  • If you add a beanio.properties file to your classpath, BeanIO will use it to override its default settings. – Kevin Aug 21 '13 at 04:09