Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top