固定长度 xsd 中的最后一个字段被设置为空

问题描述

我正在尝试将固定长度文件中的记录映射到 POJO。

定长文件内容如下

AlexSA1
JoeyCA0BNB
CarlPM1B B

映射如下

<record name="xyz" class="POJO">
     <field name="name" type="string" position="0" length="4" required="false"/>
     <field name="state" type="string" position="4" length="2" required="true"/>
     <field name="enrolled" position="6" type="byte" length="1" required="true"/>
     <field name="label1" type="string" position="7" length="1" minOccurs="0"/>
     <field name="label2" type="string"  position="8" length="1" minOccurs="0"/>
     <field name="label3" type="string"  position="9" length="1" minOccurs="0"/>
</record>

结果 pojo 看起来像这样

{Alex,SA,1,null,null}. //all the last feilds are setting to null
{Joey,CA,B,N,N}
{Carl,PM,N} //it's not being set to null

如果值不存在,我想将其映射为空

所以,POJO 应该看起来像

 {Alex,} //all the last feilds are setting to empty
 {Joey,N}
 {Carl,N} 

我该怎么做?

解决方法

我从未使用过 bean.io,但我怀疑您需要为字段提供默认值。见Field properties