【问题标题】:BeanIO - "Too few fields, expected 8 minimum", why?BeanIO - “字段太少,预计最少 8 个”,为什么?
【发布时间】:2012-10-18 10:50:48
【问题描述】:

我在 java 中使用 BeanIO 1.2,这是我的映射:

  <stream name="RecordImport" format="delimited">
    <record name="Record" minOccurs="1" maxOccurs="unbounded" class="com.myclasses.Record">
      <field name="date" type="date" format="MM/dd/yyyy" trim="true"/>
      <field name="user" type="string" trim="true"/>
      <field name="storage" type="string" trim="true"/>
      <field name="product" type="string" trim="true"/>
      <field name="qty" type="bigdecimal" format="#,##0" trim="true"/>
      <field name="altQty1" type="bigdecimal" format="#,##0" trim="true"/>
      <field name="altQty2" type="bigdecimal" format="#,##0" trim="true"/>
      <field name="altQty3" type="bigdecimal" format="#,##0" trim="true"/>
    </record>
  </stream>

我的文本文件如下所示:

3/11/2012   lpq 200011  RDD1006 8           
3/11/2012   lpq 200011  RDD1006 8           
3/11/2012   lpq 200011  RDD1006 8   1   2   3
3/11/2012   lpq 200011  RDD1006 8           

结果是我收到这条消息:

"- Line 4: Too few fields, expected 8 minimum."

现在这很奇怪,因为我确实有适当的选项卡来指示第四行有 8 个字段。这似乎是因为第 4 行中的最后一个树字段为空。我需要使它们为空的能力,但不引发此消息。同样奇怪的是,这只发生在第 4 行而不是第 1 行或第 2 行。

有什么想法吗?

【问题讨论】:

  • 您可以尝试将minOccurs="0" 添加到您的可选&lt;field&gt; 声明中吗?另见:beanio.org/2.0/docs/reference/index.html#NullFields
  • 你必须使用制表符吗?您可以在文件中使用逗号吗?那会更明确
  • @Tomasz Nurkiewicz 当我将 minOccurs="0" 添加到我的可选字段时,我得到了这个异常:“minOccurs 必须为 1,或者必须设置字段集合类型。”
  • 有人有其他想法吗?
  • 第 4 行有记录终止符吗?

标签: java parsing text-parsing bean-io


【解决方案1】:

如果不删除尾随字段/选项卡之一,我无法重新创建您看到的问题(使用 BeanIO 1.2.5)。如果它们确实是可选的,您可以在记录定义上设置 minLength="5"。 BeanIO 2.x 更灵活一些,并且允许您在尾随可选字段上设置 minOccurs="0"...

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多