微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决固定长度 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。