gpt4 book ai didi

java - BeanIO - 预计至少出现 1 次

转载 作者:行者123 更新时间:2023-12-01 18:45:09 24 4
gpt4 key购买 nike

我最近将 BeanIO 框架升级到 2.0.6 版本,以将我的平面(制表符分隔)文件解析为 java 对象,我注意到如此奇怪的行为。我不能在最后一个文件行中将字段保留为空,因为 BeanIO 向我抛出此错误消息:“预计至少出现 1 次。”

我什至尝试将整个记录的 maxLength 设置为 4,以便它考虑到末尾的额外空字段,但它仍然抛出该异常。奇怪的是,它只对最后一行执行此操作,而不对其他行中的空字段执行此操作。

映射:

<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>

文件:

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

有人对如何禁用这种行为有任何想法吗?我查看了 beanio.properties 但无法修改,因为它已锁定。

最佳答案

使用 BeanIO 2.0 或更高版本,您必须使用 minOccurs="0"配置输入流中可能不存在的字段。

关于java - BeanIO - 预计至少出现 1 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18088636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com